我得到并且错误表明应用无法销毁活动
private JMDNSService jmdnsService = null;
@Override
public void onDestroy() {
super.onDestroy();
jmdnsService = null; // destroy this object so we don't keep polling.
if (D) {Log.i(TAG, "++++ ON DESTROY +++++"); }
try {
stopJMDNS();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
stopWifi();
}
private void stopWifi() {
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(false);
}
private void stopJMDNS() throws IOException {
jmdnsService.shutDownJmDNS();
}
来自JMDNSService.java的代码:
public boolean shutDownJmDNS(){
if(jmdns != null){
try {
jmdns.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
return true;
}
return false;
}
这是它产生的输出的logcat:
01-11 19:19:54.528: E/AndroidRuntime(754): FATAL EXCEPTION: main
01-11 19:19:54.528: E/AndroidRuntime(754): java.lang.RuntimeException: Unable to destroy activity {com.whooznear.android/com.whooznear.android.WhoozNearActivity}: java.lang.NullPointerException
01-11 19:19:54.528: E/AndroidRuntime(754): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:2950)
01-11 19:19:54.528: E/AndroidRuntime(754): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:2968)
01-11 19:19:54.528: E/AndroidRuntime(754): at android.app.ActivityThread.access$1100(ActivityThread.java:122)
01-11 19:19:54.528: E/AndroidRuntime(754): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1057)
01-11 19:19:54.528: E/AndroidRuntime(754): at android.os.Handler.dispatchMessage(Handler.java:99)
01-11 19:19:54.528: E/AndroidRuntime(754): at android.os.Looper.loop(Looper.java:132)
01-11 19:19:54.528: E/AndroidRuntime(754): at android.app.ActivityThread.main(ActivityThread.java:4123)
01-11 19:19:54.528: E/AndroidRuntime(754): at java.lang.reflect.Method.invokeNative(Native Method)
01-11 19:19:54.528: E/AndroidRuntime(754): at java.lang.reflect.Method.invoke(Method.java:491)
01-11 19:19:54.528: E/AndroidRuntime(754): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
01-11 19:19:54.528: E/AndroidRuntime(754): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
01-11 19:19:54.528: E/AndroidRuntime(754): at dalvik.system.NativeStart.main(Native Method)
01-11 19:19:54.528: E/AndroidRuntime(754): Caused by: java.lang.NullPointerException
01-11 19:19:54.528: E/AndroidRuntime(754): at com.whooznear.android.WhoozNearActivity.stopJMDNS(WhoozNearActivity.java:488)
01-11 19:19:54.528: E/AndroidRuntime(754): at com.whooznear.android.WhoozNearActivity.onDestroy(WhoozNearActivity.java:447)
01-11 19:19:54.528: E/AndroidRuntime(754): at android.app.Activity.performDestroy(Activity.java:4561)
01-11 19:19:54.528: E/AndroidRuntime(754): at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1078)
01-11 19:19:54.528: E/AndroidRuntime(754): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:2937)
01-11 19:19:54.528: E/AndroidRuntime(754): ... 11 more
出于某种原因,它不会让我破坏我的活动?任何想法都会有所帮助。
答案 0 :(得分:9)
: - d
jmdnsService = null;
以后几行:
jmdnsService.shutDownJmDNS();
你真的需要更多解释吗?