-2

这是我正在接受的输出:

10-09 21:57:56.344: W/dalvikvm(3141): threadid=1: thread exiting with uncaught exception (group=0x40cb8378)
10-09 21:57:56.364: E/AndroidRuntime(3141): FATAL EXCEPTION: main
10-09 21:57:56.364: E/AndroidRuntime(3141): java.lang.IllegalStateException: Activity has been destroyed
10-09 21:57:56.364: E/AndroidRuntime(3141):     at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1329)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:548)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:532)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at com.trade.MainActivity.showFragment(MainActivity.java:85)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at com.trade.MainActivity.showSettingsFragment(MainActivity.java:179)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at com.trade.Home.setting(Home.java:40)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at com.trade.Home.onOptionsItemSelected(Home.java:31)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at android.app.Activity.onMenuItemSelected(Activity.java:2534)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:353)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:964)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at com.android.internal.view.menu.ListMenuPresenter.onItemClick(ListMenuPresenter.java:166)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at android.widget.AdapterView.performItemClick(AdapterView.java:298)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:2859)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at android.widget.AbsListView$1.run(AbsListView.java:3533)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at android.os.Handler.handleCallback(Handler.java:615)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at android.os.Looper.loop(Looper.java:213)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at android.app.ActivityThread.main(ActivityThread.java:4787)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at java.lang.reflect.Method.invokeNative(Native Method)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at java.lang.reflect.Method.invoke(Method.java:511)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
10-09 21:57:56.364: E/AndroidRuntime(3141):     at dalvik.system.NativeStart.main(Native Method)
10-09 21:57:58.847: I/Process(3141): Sending signal. PID: 3141 SIG: 9

我不知道这个例外。请帮助我理解它。

谢谢

4

1 回答 1

0

我会尽力回答你关于异常的一般性问题,因为那是你所问的。如果您需要针对应用程序中特定错误的特定帮助,您需要在MainActivity此处发布(尤其是第 85 行附近的部分)。

你得到的异常是一个 android 系统异常,它告诉你你正在一个Activity不再“活着”的东西上运行。这非常容易实现,并且很可能与不正确的变量管理(或问题下方的评论中提到的不正确的实例管理)有关。不要Activity通过new操作员自己构建实例)。一个例子可能如下

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class MyActivity extends Activity {

    public static Activity instance;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (instance != null) {
            instance.setContentView(R.layout.myLayout);
        }

        instance = this;

        finish();
        startActivity(new Intent(this, MyActivity.class));
    }
}

正如您在这个简单示例中可能认识到的那样,该变量instance仅在第一次重新进入活动时才被读取!但是那里仍然引用了旧的(现在“死的”)活动。那么系统应该怎么做呢?对这个“死”活动执行操作?不,它会给你上面看到的异常

简而言之:很可能您有一个Fragment、一个Dialog或另一个 UI 的组成部分“操作”一个“死”活动(操作 = 使用对它的引用或FragmentManager来自它的一些资源(...) )

正如我所说,您的错误可能很容易修复,请将您的代码提供给我们,我们将能够提供帮助。但也许你甚至可以使用上述信息自己修复它——我想这肯定会让你自己更满意:)

于 2013-10-09T14:21:13.043 回答