Unable to Destroy Android Activity

4.9k views Asked by At

I'm getting and error that states the app is unable to destroy the activity

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();
}

Code from 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;
}

Here is the logcat from the output it is producing:

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

For some reason it won't let me destroy my activity? Any ideas would be helpful.

1

There are 1 answers

0
Waza_Be On BEST ANSWER

:-D

 jmdnsService = null;

and a few lines after:

 jmdnsService.shutDownJmDNS();

Do you really need more explanations?