app will crash when the http connection is closed or unstable !
Opened this issue · 5 comments
When I close all network connection, my app will be crashed .
It seems I need to catch some exception in some where , anyone can help me ?
10-30 05:38:03.368 22951-22951/com.ilivecn.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116)
at org.json.JSONTokener.nextValue(JSONTokener.java:94)
at org.json.JSONObject.(JSONObject.java:154)
at org.json.JSONObject.(JSONObject.java:171)
at com.zsoft.signala.transport.longpolling.JSONHelper.ToJSONObject(JSONHelper.java:12)
at com.zsoft.signala.transport.longpolling.ConnectingState$1.onComplete(ConnectingState.java:56)
at com.turbomanage.httpclient.android.DoHttpRequestTask.onPostExecute(DoHttpRequestTask.java:56)
at com.turbomanage.httpclient.android.DoHttpRequestTask.onPostExecute(DoHttpRequestTask.java:1)
at android.os.AsyncTask.finish(AsyncTask.java:631)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5493)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
at dalvik.system.NativeStart.main(Native Method)
In what way do you close all network connections?
I found the point. When connection be disconnected, httpResponse.getBodyString() will return null.
so I modify JSONHelper.java to this, It work fine.
public class JSONHelper {
public static JSONObject ToJSONObject(String text)
{
JSONObject json;
if (text == null) {
return null;
}
try {
json = new JSONObject(text);
} catch (JSONException e) {
json = null;
}
return json;
}
}
It seems to be same with your code ,but when I changed to this , It never be crashed again. I don't know why...
By the way , I disconnected all network by disable mobile wifi and close gprs .
Modify JSONHelper.java to this, it will return null when it throw some Exception, and write Exception to Log if it have other Exception.
public class JSONHelper {
public static JSONObject ToJSONObject(String text)
{
JSONObject json = null;
try {
json = new JSONObject(text);
} catch (JSONException e) {
} catch (NullPointerException e){
} catch (Exception e){
//Log it
}
return json;
}
}
can you fix this and include in signala-longpolling-0.20.aar? I'm use Eclipse Juno, and cant modify .class file without decompile.
can you fix this and include in signala-longpolling-0.20.aar.