我有一个soap webservice和一个用于调用服务的android应用程序。应用程序始终有效,但在上次webservice更新后出现问题。 webservice的更新仅用于删除一些未使用的服务。其他代码未修改。 我的android应用程序使用AsyncTask来调用服务并获取结果:
public class DownloadDataTask extends AsyncTask<Void, Void, Vector<SoapObject>> {
private static String METHOD_NAME = "getData";
private static String SOAP_ACTION = "http://example.com/getData";
private static String URL = "http://arduino-data-server.appspot.com/dataserver";
private static String NAMESPACE = "http://example.com/";
@SuppressWarnings("unchecked")
@Override
protected Vector<SoapObject> doInBackground(Void... arg0) {
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
Vector<SoapObject> result = (Vector<SoapObject>) envelope.getResponse();
return result;
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
return null;
}
但我得到了后续错误:
10-11 18:36:25.063: E/AndroidRuntime(9250): FATAL EXCEPTION: AsyncTask #1
10-11 18:36:25.063: E/AndroidRuntime(9250): java.lang.RuntimeException: An error occured while executing doInBackground()
10-11 18:36:25.063: E/AndroidRuntime(9250): at android.os.AsyncTask$3.done(AsyncTask.java:299)
10-11 18:36:25.063: E/AndroidRuntime(9250): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
10-11 18:36:25.063: E/AndroidRuntime(9250): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
10-11 18:36:25.063: E/AndroidRuntime(9250): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
10-11 18:36:25.063: E/AndroidRuntime(9250): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
10-11 18:36:25.063: E/AndroidRuntime(9250): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
10-11 18:36:25.063: E/AndroidRuntime(9250): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
10-11 18:36:25.063: E/AndroidRuntime(9250): at java.lang.Thread.run(Thread.java:841)
10-11 18:36:25.063: E/AndroidRuntime(9250): Caused by: java.lang.ClassCastException: org.ksoap2.serialization.SoapObject cannot be cast to java.util.Vector
10-11 18:36:25.063: E/AndroidRuntime(9250): at com.example.soapclient.DownloadDataTask.doInBackground(DownloadDataTask.java:49)
10-11 18:36:25.063: E/AndroidRuntime(9250): at com.example.soapclient.DownloadDataTask.doInBackground(DownloadDataTask.java:1)
10-11 18:36:25.063: E/AndroidRuntime(9250): at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-11 18:36:25.063: E/AndroidRuntime(9250): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
10-11 18:36:25.063: E/AndroidRuntime(9250): ... 4 more
其中第49行是我调用getResult()方法的行。
出了什么问题?
答案 0 :(得分:1)
原因很清楚:
Caused by: java.lang.ClassCastException: org.ksoap2.serialization.SoapObject
cannot be cast to java.util.Vector
在此行中,您无法将结果SoapObject强制转换为Vector:
Vector<SoapObject> result = (Vector<SoapObject>) envelope.getResponse();
试试这个:
SoapObject result = (SoapObject) envelope.getResponse();