我在退出我的应用程序时遇到了这个问题:当您单击“返回”按钮时,会出现 LeadBolt ExitAd。然后您单击“否”,应用程序退出并显示“此应用程序已停止”的 toast。
所以,有一些广告或将 MediaPlayer 设置为空。
代码如下所示:
alarm = new MediaPlayer();
...
@Override
public void onPause() {
super.onPause();
if (alarm != null) {
alarm.release();
alarm = null;
}
}
@Override
public void onStop() {
super.onStop();
if (alarm != null) {
alarm.release();
alarm = null;
}
}
public void onDestroy() {
myController.destroyAd();
// myController2.destroyAd();
if (adView != null) {
adView.destroy();
}
super.onDestroy();
if (alarm != null) {
alarm.release();
alarm = null;
}
}
异常日志:
11-05 11:06:49.130: E/AndroidRuntime(2019): FATAL EXCEPTION: main
11-05 11:06:49.130: E/AndroidRuntime(2019): java.lang.RuntimeException: Unable to destroy activity {com.klangstudios.car_pilot_remote/com.my_company.my_app.MainActivity}: java.lang.NullPointerException
11-05 11:06:49.130: E/AndroidRuntime(2019): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3451)
11-05 11:06:49.130: E/AndroidRuntime(2019): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3469)
11-05 11:06:49.130: E/AndroidRuntime(2019): at android.app.ActivityThread.access$1200(ActivityThread.java:141)
11-05 11:06:49.130: E/AndroidRuntime(2019): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1287)
11-05 11:06:49.130: E/AndroidRuntime(2019): at android.os.Handler.dispatchMessage(Handler.java:99)
11-05 11:06:49.130: E/AndroidRuntime(2019): at android.os.Looper.loop(Looper.java:137)
11-05 11:06:49.130: E/AndroidRuntime(2019): at android.app.ActivityThread.main(ActivityThread.java:5041)
11-05 11:06:49.130: E/AndroidRuntime(2019): at java.lang.reflect.Method.invokeNative(Native Method)
11-05 11:06:49.130: E/AndroidRuntime(2019): at java.lang.reflect.Method.invoke(Method.java:511)
11-05 11:06:49.130: E/AndroidRuntime(2019): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-05 11:06:49.130: E/AndroidRuntime(2019): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-05 11:06:49.130: E/AndroidRuntime(2019): at dalvik.system.NativeStart.main(Native Method)
11-05 11:06:49.130: E/AndroidRuntime(2019): Caused by: java.lang.NullPointerException
11-05 11:06:49.130: E/AndroidRuntime(2019): at com.klangstudios.car_pilot_remote.MainActivity.onDestroy(MainActivity.java:209)
11-05 11:06:49.130: E/AndroidRuntime(2019): at android.app.Activity.performDestroy(Activity.java:5273)
11-05 11:06:49.130: E/AndroidRuntime(2019): at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1110)
11-05 11:06:49.130: E/AndroidRuntime(2019): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3438)
11-05 11:06:49.130: E/AndroidRuntime(2019): ... 11 more
有人遇到过类似的问题吗?