1

下面的代码有一个奇怪的错误:一切都可以正常工作几个小时,但有时我有一个异常并且我的应用程序关闭了。

这是我经常调用的一段代码(每 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 库中。

此致

吉安

4

0 回答 0