适用于Android的KSOAP2会产生偶发错误

时间:2013-01-22 14:31:42

标签: java android nullpointerexception ksoap2

我在下面的代码中遇到了一个奇怪的错误:所有工作都运行了好几个小时,但有时我会遇到异常,我的应用程序会关闭。

这是我经常调用的代码(每15秒)

String URL = wscfg.server_address + "/xmds.php";
SoapObject localSoapObject = new SoapObject("", "registerDisplay");
localSoapObject.addProperty("serverKey", wscfg.server_key);
localSoapObject.addProperty("hardwareKey", wscfg.hardware_key);
localSoapObject.addProperty("version", wscfg.server_version);
localSoapObject.addProperty("displayName", wscfg.device_name);
SoapSerializationEnvelope localSoapSerializationEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
localSoapSerializationEnvelope.bodyOut = localSoapObject;
new HttpTransportSE(URL).call("", localSoapSerializationEnvelope);
String s = (String)localSoapSerializationEnvelope.getResponse();

例外是:

01-22 13:33:55.048: E/AndroidRuntime(567): FATAL EXCEPTION: Timer-5
01-22 13:33:55.048: E/AndroidRuntime(567): java.lang.NullPointerException
01-22 13:33:55.048: E/AndroidRuntime(567):  at org.ksoap2.transport.ServiceConnectionSE.getResponseProperties(ServiceConnectionSE.java:85)
01-22 13:33:55.048: E/AndroidRuntime(567):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:189)
01-22 13:33:55.048: E/AndroidRuntime(567):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:114)
01-22 13:33:55.048: E/AndroidRuntime(567):  at com.gmgunderground.test.xmds.WebServiceManager.requiredFiles(WebServiceManager.java:66)
01-22 13:33:55.048: E/AndroidRuntime(567):  at com.gmgunderground.test.xmds.XmdsService.TimerSchedulerSupervisor(XmdsService.java:267)
01-22 13:33:55.048: E/AndroidRuntime(567):  at com.gmgunderground.test.xmds.XmdsService.access$1(XmdsService.java:248)
01-22 13:33:55.048: E/AndroidRuntime(567):  at com.gmgunderground.test.xmds.XmdsService$3.run(XmdsService.java:552)
01-22 13:33:55.048: E/AndroidRuntime(567):  at java.util.Timer$TimerImpl.run(Timer.java:284)

如何解决此错误?有没有办法阻止应用程序关闭并仅返回null?正如我从logcat中看到的那样,错误在KSOAP2 Android库中。

祝你好运

吉安

0 个答案:

没有答案