0

下面是我的代码。当我单击“addDebtor”按钮时,它给了我一个错误:应用程序债务跟踪器(进程 biz.midl.debttracker)已意外停止。请再试一次。

我在我的 IDE 中找不到任何错误。我检查了按钮的名称,它匹配。我检查了我的其他活动的名称,它也匹配。

有任何想法吗?

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button getAnswerButton = (Button) findViewById(R.id.addDebtor);

    getAnswerButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, addDebt.class));

        }
    });
}  

}

Logcat 错误是:

09-12 06:03:49.744: D/AndroidRuntime(246): Shutting down VM
09-12 06:03:49.744: W/dalvikvm(246): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
09-12 06:03:49.765: E/AndroidRuntime(246): FATAL EXCEPTION: main
09-12 06:03:49.765: E/AndroidRuntime(246): android.content.ActivityNotFoundException: Unable to find explicit activity class {biz.midl.debttracker/biz.midl.debttracker.addDebt}; have you declared this activity in your AndroidManifest.xml?
09-12 06:03:49.765: E/AndroidRuntime(246):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
09-12 06:03:49.765: E/AndroidRuntime(246):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
09-12 06:03:49.765: E/AndroidRuntime(246):  at android.app.Activity.startActivityForResult(Activity.java:2817)
09-12 06:03:49.765: E/AndroidRuntime(246):  at android.app.Activity.startActivity(Activity.java:2923)
09-12 06:03:49.765: E/AndroidRuntime(246):  at biz.midl.debttracker.MainActivity$1.onClick(MainActivity.java:22)
09-12 06:03:49.765: E/AndroidRuntime(246):  at android.view.View.performClick(View.java:2408)
09-12 06:03:49.765: E/AndroidRuntime(246):  at android.view.View$PerformClick.run(View.java:8816)
09-12 06:03:49.765: E/AndroidRuntime(246):  at android.os.Handler.handleCallback(Handler.java:587)
09-12 06:03:49.765: E/AndroidRuntime(246):  at android.os.Handler.dispatchMessage(Handler.java:92)
09-12 06:03:49.765: E/AndroidRuntime(246):  at android.os.Looper.loop(Looper.java:123)
09-12 06:03:49.765: E/AndroidRuntime(246):  at android.app.ActivityThread.main(ActivityThread.java:4627)
09-12 06:03:49.765: E/AndroidRuntime(246):  at java.lang.reflect.Method.invokeNative(Native Method)
09-12 06:03:49.765: E/AndroidRuntime(246):  at java.lang.reflect.Method.invoke(Method.java:521)
09-12 06:03:49.765: E/AndroidRuntime(246):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-12 06:03:49.765: E/AndroidRuntime(246):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-12 06:03:49.765: E/AndroidRuntime(246):  at dalvik.system.NativeStart.main(Native Method)
09-12 06:08:54.834: D/AndroidRuntime(277): Shutting down VM
09-12 06:08:54.834: W/dalvikvm(277): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
09-12 06:08:54.845: E/AndroidRuntime(277): FATAL EXCEPTION: main
09-12 06:08:54.845: E/AndroidRuntime(277): android.content.ActivityNotFoundException: Unable to find explicit activity class {biz.midl.debttracker/biz.midl.debttracker.addDebt}; have you declared this activity in your AndroidManifest.xml?
09-12 06:08:54.845: E/AndroidRuntime(277):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
09-12 06:08:54.845: E/AndroidRuntime(277):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
09-12 06:08:54.845: E/AndroidRuntime(277):  at android.app.Activity.startActivityForResult(Activity.java:2817)
09-12 06:08:54.845: E/AndroidRuntime(277):  at android.app.Activity.startActivity(Activity.java:2923)
09-12 06:08:54.845: E/AndroidRuntime(277):  at biz.midl.debttracker.MainActivity$1.onClick(MainActivity.java:22)
09-12 06:08:54.845: E/AndroidRuntime(277):  at android.view.View.performClick(View.java:2408)
09-12 06:08:54.845: E/AndroidRuntime(277):  at android.view.View$PerformClick.run(View.java:8816)
09-12 06:08:54.845: E/AndroidRuntime(277):  at android.os.Handler.handleCallback(Handler.java:587)
09-12 06:08:54.845: E/AndroidRuntime(277):  at android.os.Handler.dispatchMessage(Handler.java:92)
09-12 06:08:54.845: E/AndroidRuntime(277):  at android.os.Looper.loop(Looper.java:123)
09-12 06:08:54.845: E/AndroidRuntime(277):  at android.app.ActivityThread.main(ActivityThread.java:4627)
09-12 06:08:54.845: E/AndroidRuntime(277):  at java.lang.reflect.Method.invokeNative(Native Method)
09-12 06:08:54.845: E/AndroidRuntime(277):  at java.lang.reflect.Method.invoke(Method.java:521)
09-12 06:08:54.845: E/AndroidRuntime(277):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-12 06:08:54.845: E/AndroidRuntime(277):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-12 06:08:54.845: E/AndroidRuntime(277):  at dalvik.system.NativeStart.main(Native Method)
4

4 回答 4

1

您需要在 中声明您的addDebt活动AndroidManifest.xml

<activity
            android:name="biz.midl.debttracker.addDebt"
            android:label="@string/app_name" >
  </activity>

biz.midl.debttracker是您的packageName.

于 2013-09-12T06:14:27.363 回答
0

尝试使用这个:

 Button getAnswerButton = (Button) findViewById(R.id.addDebtor);

    getAnswerButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

             Intent start = new Intent (MainActivity.this,
                                        addDebt.class
                                     );
            startActivity(start);

        }
    });
于 2013-09-12T06:10:21.350 回答
0

你要么没有在你的清单文件中添加你的活动,要么你的 addDebt.class 应该是 AddDebt.class,请遵循类名约定。

于 2013-09-12T06:14:05.000 回答
0

将此添加到您的清单中

<activity android:name="your package.addDebt" />
于 2013-09-12T06:15:37.897 回答