无法销毁 Android Activity

发布于 2024-12-26 06:12:46 字数 3378 浏览 0 评论 0原文

我收到错误消息,指出应用程序无法销毁

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

出于某种原因,它不会让我销毁我的活动?任何想法都会有帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过去的过去 2025-01-02 06:12:46

:-D

 jmdnsService = null;

以及之后的几行:

 jmdnsService.shutDownJmDNS();

您真的需要更多解释吗?

:-D

 jmdnsService = null;

and a few lines after:

 jmdnsService.shutDownJmDNS();

Do you really need more explanations?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文