按下后退按钮后记录:
11-07 22:48:08.376:D / AndroidRuntime(5325):关闭VM 11-07 22:48:08.376:W / dalvikvm(5325):threadid = 1:线程退出时未捕获异常(group = 0x4162d700) 11-07 22:48:08.384:E / AndroidRuntime(5325):致命异常:主要 11-07 22:48:08.384:E / AndroidRuntime(5325):java.lang.RuntimeException:无法销毁活动
{com.some.pack / com.some.packNY}: java.lang.NullPointerException 11-07 22:48:08.384: E / AndroidRuntime(5325):at android.app.ActivityThread.performDestroyActivity
(ActivityThread.java:3627)11-07 22:48:08.384:E / AndroidRuntime(5325): 在 android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3645) 11-07 22:48:08.384:E / AndroidRuntime(5325):at android.app.ActivityThread.access $ 1200(ActivityThread.java:153)11-07 22:48:08.384:E / AndroidRuntime(5325):at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1322) 11-07 22:48:08.384:E / AndroidRuntime(5325):at android.os.Handler.dispatchMessage(Handler.java:99)11-07 22:48:08.384:E / AndroidRuntime(5325):at android.os.Looper.loop(Looper.java:137)11-07 22:48:08.384: E / AndroidRuntime(5325):at android.app.ActivityThread.main(ActivityThread.java:5289)11-07 22:48:08.384:E / AndroidRuntime(5325):at java.lang.reflect.Method.invokeNative(Native Method)11-07 22:48:08.384:E / AndroidRuntime(5325):at java.lang.reflect.Method.invoke(Method.java:525)11-07 22:48:08.384: E / AndroidRuntime(5325):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run
(ZygoteInit.java:739)11-07 22:48:08.384:E / AndroidRuntime(5325):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)11-07 22:48:08.384:E / AndroidRuntime(5325):at dalvik.system.NativeStart.main(Native Method)11-07 22:48:08.384: E / AndroidRuntime(5325):引起:java.lang.NullPointerException 11-07 22:48:08.384:E / AndroidRuntime(5325):at com.some.pack.NY.stop(NY.java:100)11-07 22:48:08.384: E / AndroidRuntime(5325):at com.some.pack.onDestroy(NY.java:106)11-07 22:48:08.384:E / AndroidRuntime(5325):at android.app.Activity.performDestroy(Activity.java:5302)11-07 22:48:08.384:E / AndroidRuntime(5325):at android.app.Instrumentation.callActivityOnDestroy
(Instrumentation.java:1117)11-07 22:48:08.384: E / AndroidRuntime(5325):at android.app.ActivityThread.performDestroyActivity
(ActivityThread.java:3614)11-07 22:48:08.384:E / AndroidRuntime(5325): ... 11更多11-07 22:48:08.392:W / ActivityManager(408):强制 整理活动com.some.pack / .MainActivity 11-07 22:48:09.079:W / ActivityManager(408):活动暂停超时 ActivityRecord {41985990 u0
com.some.pack / .MainActivity} 11-07 22:48:09.095: W /设置(4780):设置bugreport_in_power_menu已从中移除 android.provider.Settings.Secure到
android.provider.Settings.Global。 11-07 22:48:09.095:E / Cryptfs(124): 没有运行加密,中止11-07 22:48:09.923: I /处理(5325):发送信号。 PID:5325 SIG:9 11-07 22:48:09.946: W / InputDispatcher(408):channel'419e2ff0 com.some.pack / com.some.pack.MainActivity(server)'〜Consumer
关闭输入通道或发生错误。 events = 0x9 11-07 22:48:09.946:E / InputDispatcher(408):channel'419e2ff0 com.some.pack / com.some.pack.MainActivity(server)'〜频道是
不可挽回地破碎并将被处置!
答案 0 :(得分:1)
由于你没有发布日志,所以有点难以弄清楚,但是你的实现中肯定会有一个巨大的差距,它将以NullPointerException结束,你在点击监听器中初始化“mp”和“mp2” ,并在onDestroy中停止它们,但是你没有检查方法“停止”中的空值,这肯定会导致NPE,如果你去活动,并且不要按下播放的按钮并为“mp”分配值和mp2“引用然后按回来,并调用onDestroy(调用停止),CRASH!因为mp和mp2是空的......
希望有帮助。
问候!
答案 1 :(得分:0)
在onPrepared()onStop()onDestroy()和onCompletin()中添加一个简单的if条件:
if(mp != null && mp2 != null){
// Now You wont get runTime problems.
}