当前位置: 首页 > 工具软件 > Lang switcher > 使用案例 >

java 捕获 nullpointerexception,Android上无法捕获java.lang.NullPointerException

姚兴安
2023-12-01

错误:

java.lang.NullPointerException

at com.lala.Home.hideLoadinganimation(Home.java:969)

at com.lala.Home.access$4(Home.java:967)

at com.lala.Home$17.onFinish(Home.java:892)

at com.loopj.android.http.AsyncHttpResponseHandler.handleMessage (AsyncHttpResponseHandler.java:180)

at com.loopj.android.http.AsyncHttpResponseHandler$1.handleMessage(AsyncHttpResponseHandler.java:86)

at android.os.Handler.dispatchMessage(Handler.java:99)

at android.os.Looper.loop(Looper.java:130)

at android.app.ActivityThread.main(ActivityThread.java:3687)

at java.lang.reflect.Method.invokeNative(Native Method)

at java.lang.reflect.Method.invoke(Method.java:507)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)

at dalvik.system.NativeStart.main(Native Method)我知道为什么会发生,不知何故,用户隐藏/退出或转到其他应用程序,就像我的应用程序完成从服务器加载数据并刚刚隐藏进度对话框一样。

我试图在下面的块中捕捉它,但它不起作用。我错过了什么?

private void hideLoadinganimation(boolean asDialog) {

try {

if (asDialog) {

try {

pDialog.dismiss();

} catch (Exception e) {

e.printStackTrace();

// again, sometimes pDialog is null. I have no idea why as I

// can't reproduce it.

}

} else {

switcher.showPrevious();

}

} catch (Exception ee) {

ee.printStackTrace();

}

}

 类似资料: