我有一个肥皂网络服务和一个用于调用服务的 android 应用程序。应用程序总是可以工作,但在上次 web 服务更新后,出现了问题。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() 方法的行。
怎么了?