我知道当我连接到互联网时我得到这个例外的条件,但互联网没有服务,所以我的请求到服务器的时间,但我无法处理响应..之后我得到这个例外。
//我得到了NullPointerException on response= envelope.getResponse();
class Logintask extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
setmainloader(1);
}
@Override
protected String doInBackground(String... args) {
String NAMESPACE = "URL";
String URL = "API Call";
String SOAP_ACTION = "Validate user api";
String METHOD_NAME = "Some method";
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Request.addProperty("TokenID", sm.getUserDetails().get(SessionManager.TOKEN_ID));
Request.addProperty("UserName", enteredusername);
Request.addProperty("Pwd", enteredpassword);
Request.addProperty("GCMID", " ");
Request.addProperty("Imei", imei);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(Request);
HttpTransportSE httpTransport = new HttpTransportSE(URL, 20000);
try {
httpTransport.call(SOAP_ACTION, envelope);
} catch (SocketTimeoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
//CHECK FOR RESPONSE
Log.d("check for response", "doInBackground: ");
//我在这里得到例外????当我得到这个响应时//连接没有wifi或移动数据,但互联网没有来。
response=envelope.getResponse();
// Log.d("response",response.toString());
} catch (SoapFault e) {
// TODO Auto-generated catch block
}
return null;
}
这是我的日志
致命异常:AsyncTask#6 过程:com.virtuzoconsultancyservicespvtltd.attendenceapp,PID:13903 java.lang.RuntimeException:执行时发生错误 doInBackground() 在android.os.AsyncTask $ 3.done(AsyncTask.java:309) 在java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354) at java.util.concurrent.FutureTask.setException(FutureTask.java:223) 在java.util.concurrent.FutureTask.run(FutureTask.java:242) 在android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:234) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:588) 在java.lang.Thread.run(Thread.java:818) 引起:java.lang.NullPointerException:尝试调用接口方法 'int org.ksoap2.serialization.KvmSerializable.getPropertyCount()'在一个 null对象引用 在org.ksoap2.serialization.SoapSerializationEnvelope.getResponse(SoapSerializationEnvelope.java:521) 在com.vcpl.attendenceappnew.EmailDialog $ mailattendance.doInBackground(EmailDialog.java:224) 在com.vcpl.attendenceappnew.EmailDialog $ mailattendance.doInBackground(EmailDialog.java:175) 在android.os.AsyncTask $ 2.call(AsyncTask.java:295) 在java.util.concurrent.FutureTask.run(FutureTask.java:237) 在android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:234) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:588) 在java.lang.Thread.run(Thread.java:818)
答案 0 :(得分:1)
更改此
response=envelope.getResponse();
到这个
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();