0
我想通過SOAP web服務從服務器獲取圖像到android應用程序中。我在那裏得到一些錯誤。 我想從Web服務接收字節數組中的圖像。 我的代碼是 -從soap web服務中獲取圖像到android應用程序時出錯
Web服務代碼是 -
@WebMethod(operationName = "GetDiseasePic")
public byte[] picFromServer(@WebParam(name = "file_name") String filename) {
String filePath = "C:/Users/Ashraful/Desktop/layout/icons/" + filename;
System.out.println("Sending file: " + filePath);
try {
File file = new File(filePath);
FileInputStream fis = new FileInputStream(file);
BufferedInputStream inputStream = new BufferedInputStream(fis);
byte[] fileBytes = new byte[(int) file.length()];
inputStream.read(fileBytes);
inputStream.close();
return fileBytes;
} catch (IOException ex) {
System.err.println(ex);
throw new WebServiceException(ex);
}
}
我的Android應用程序是 -
private void imageSelect() {
final String NAMESPACE_D_PIC = "http://DiseaseInformationWS/"; // target namespace of the Web service available
final String METHOD_NAME_D_PIC = "GetDiseasePic";// Name of the method in the Webservice file
final String SOAP_ACTION_D_PIC = "http://DiseaseInformationWS/GetDiseasePic"; // SoapAction that consists of the NAMESPACE+ METHOD_NAME1
final String URL_D_PIC = "http://"+IpchangeInteface.IPADDRESS+":8080/AshrafThesisWebService/DiseaseWebSer vice?wsdl";
new AsyncTask<String,Void, Bitmap>(){
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Bitmap doInBackground(String... params) {
SoapObject request_d_pic = new SoapObject(NAMESPACE_D_PIC,METHOD_NAME_D_PIC);
request_d_pic.addProperty("file_name",imagefilename);
SoapSerializationEnvelope envelop_d_pic = new SoapSerializationEnvelope(SoapEnvelope.VER10);
envelop_d_pic.setOutputSoapObject(request_d_pic);
HttpTransportSE androidHttpTransport_d_pic = new HttpTransportSE(URL_D_PIC);
try {
androidHttpTransport_d_pic.call(SOAP_ACTION_D_PIC,envelop_d_pic);
SoapObject result_d_pic = (SoapObject) envelop_d_pic.bodyIn;
SoapObject result_d_picSP = (SoapObject) envelop_d_pic.bodyIn;
String getresult = result_d_pic.toString();
Log.d("IMAGEFILE",getresult);
if (getresult!=""){
filebyte = Base64.decode(getresult,Base64.DEFAULT);
bitmapImage = BitmapFactory.decodeByteArray(filebyte,0,filebyte.length);
}
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
return bitmapImage;
}
@Override
protected void onPostExecute(Bitmap bitmap) {
if(bitmapImage!=null) {
diseasePic.setImageBitmap(bitmapImage);
}
}
}.execute();
}
錯誤我得到的活性是 -
05-25 20:33:47.282 3184-3249/com.thesiswork.ashraf.ashrafresearchwork E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
at java.util.concurrent.FutureTask.run(FutureTask.java:239)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:838)
Caused by: java.lang.IllegalArgumentException: bad base-64
at android.util.Base64.decode(Base64.java:161)
at android.util.Base64.decode(Base64.java:136)
at android.util.Base64.decode(Base64.java:118)
at com.thesiswork.ashraf.ashrafresearchwork.Disease_InformationScreen$5.doInBackground(Disease_InformationScreen.java:410)
at com.thesiswork.ashraf.ashrafresearchwork.Disease_InformationScreen$5.doInBackground(Disease_InformationScreen.java:384)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:838)
請建議我現在要做什麼?
它給了我同樣的錯誤,甚至將你的建議@Tabassum – Ashraf
後請人幫助我在這個問題上。 – Ashraf
如果你在數據庫中存儲你的圖像base64字符串,所以檢查字段類型是文本還是其他如果是文本然後圖像保存正常否則不是爲什麼出錯 –