-2

我正在尝试开始一项新活动,但我的应用程序停止了。如果 if 条件为真,则执行注册活动并工作,但如果为假,则跟踪活动停止我的应用程序 这是代码:

if(condition)
{
    Intent register = new Intent(HomeActivity.this, Register.class);
    HomeActivity.this.startActivity(register);
}
else
{
    Intent login = new Intent(HomeActivity.this, Track.class);
    HomeActivity.this.startActivity(login);
}

也许这与我的 Track 课程有关?

日志猫:

    12-21 15:46:16.265: D/AndroidRuntime(540): Shutting down VM
12-21 15:46:16.265: W/dalvikvm(540): threadid=1: thread exiting with uncaught exception (group=0x40c711f8)
12-21 15:46:16.265: E/AndroidRuntime(540): FATAL EXCEPTION: main
12-21 15:46:16.265: E/AndroidRuntime(540): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.location/com.example.android.location.HomeActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.android.location/com.example.android.location.Track}; have you declared this activity in your AndroidManifest.xml?
12-21 15:46:16.265: E/AndroidRuntime(540):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
12-21 15:46:16.265: E/AndroidRuntime(540):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
12-21 15:46:16.265: E/AndroidRuntime(540):  at android.app.ActivityThread.access$600(ActivityThread.java:128)
12-21 15:46:16.265: E/AndroidRuntime(540):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
12-21 15:46:16.265: E/AndroidRuntime(540):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-21 15:46:16.265: E/AndroidRuntime(540):  at android.os.Looper.loop(Looper.java:137)
12-21 15:46:16.265: E/AndroidRuntime(540):  at android.app.ActivityThread.main(ActivityThread.java:4514)
12-21 15:46:16.265: E/AndroidRuntime(540):  at java.lang.reflect.Method.invokeNative(Native Method)
12-21 15:46:16.265: E/AndroidRuntime(540):  at java.lang.reflect.Method.invoke(Method.java:511)
12-21 15:46:16.265: E/AndroidRuntime(540):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
12-21 15:46:16.265: E/AndroidRuntime(540):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
12-21 15:46:16.265: E/AndroidRuntime(540):  at dalvik.system.NativeStart.main(Native Method)
12-21 15:46:16.265: E/AndroidRuntime(540): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.android.location/com.example.android.location.Track}; have you declared this activity in your AndroidManifest.xml?
12-21 15:46:16.265: E/AndroidRuntime(540):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)
12-21 15:46:16.265: E/AndroidRuntime(540):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1388)
12-21 15:46:16.265: E/AndroidRuntime(540):  at android.app.Activity.startActivityForResult(Activity.java:3281)
12-21 15:46:16.265: E/AndroidRuntime(540):  at android.app.Activity.startActivity(Activity.java:3388)
12-21 15:46:16.265: E/AndroidRuntime(540):  at com.example.android.location.HomeActivity.onCreate(HomeActivity.java:44)
12-21 15:46:16.265: E/AndroidRuntime(540):  at android.app.Activity.performCreate(Activity.java:4562)
12-21 15:46:16.265: E/AndroidRuntime(540):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
12-21 15:46:16.265: E/AndroidRuntime(540):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
12-21 15:46:16.265: E/AndroidRuntime(540):  ... 11 more
4

4 回答 4

2
<activity android:name=".Track" />
于 2012-12-21T14:00:23.507 回答
1

这可能是因为清单中缺少马蹄莲的声明,将下面的行添加到清单中

 <activity android:name=".Track">
     <intent-filter>
          <action android:name="android.intent.action.ACTIVITY" />
     </intent-filter>
  </activity>

[补充1]

如果您查看日志,您会看到

找不到明确的活动类 {com.example.android.location/com.example.android.location.Track};您是否在 AndroidManifest.xml 中声明了此活动?

于 2012-12-21T13:56:58.137 回答
0

你必须在你的 manifest.xml 文件中声明你的活动......也许这可能是原因

于 2012-12-21T13:56:06.320 回答
0

您的 Track 类未在您的 Manifest 中声明为您的 logcat 显示。尝试在清单中添加该 Track 类。

     <activity
        android:name=".Track"
        android:label="@string/app_name">
    </activity>
于 2012-12-21T14:02:11.660 回答