標籤:
1.首先我們二話不說直接先看報錯內容如下:
07-12 08:25:03.572: E/dalvikvm(3602): native fork pid:0 done.07-12 08:25:03.582: E/dalvikvm(3602): threadid=6: created from interp,name=ReferenceQueueDaemon07-12 08:25:03.582: E/dalvikvm(3602): threadid=6: calling run(),name=ReferenceQueueDaemon07-12 08:25:03.582: E/dalvikvm(3602): threadid=7: created from interp,name=FinalizerDaemon07-12 08:25:03.582: E/dalvikvm(3602): threadid=7: calling run(),name=FinalizerDaemon07-12 08:25:03.592: E/dalvikvm(3602): threadid=8: created from interp,name=FinalizerWatchdogDaemon07-12 08:25:03.592: E/dalvikvm(3602): threadid=8: calling run(),name=FinalizerWatchdogDaemon07-12 08:25:03.642: D/ActivityThread(3602): setTargetHeapUtilization:0.2507-12 08:25:03.642: D/ActivityThread(3602): setTargetHeapIdealFree:838860807-12 08:25:03.642: D/ActivityThread(3602): setTargetHeapConcurrentStart:209715207-12 08:25:03.662: I/System.out(3602): Sending WAIT chunk07-12 08:25:03.662: W/ActivityThread(3602): Application com.himi.clock is waiting for the debugger on port 8100...07-12 08:25:05.253: I/System.out(3602): Debugger has connected07-12 08:25:05.253: I/System.out(3602): waiting for debugger to settle...07-12 08:25:05.454: I/System.out(3602): waiting for debugger to settle...07-12 08:25:05.654: I/System.out(3602): waiting for debugger to settle...07-12 08:25:05.854: I/System.out(3602): waiting for debugger to settle...07-12 08:25:06.054: I/System.out(3602): waiting for debugger to settle...07-12 08:25:06.254: I/System.out(3602): waiting for debugger to settle...07-12 08:25:06.455: I/System.out(3602): waiting for debugger to settle...07-12 08:25:06.655: I/System.out(3602): waiting for debugger to settle...07-12 08:25:06.855: I/System.out(3602): waiting for debugger to settle...07-12 08:25:07.055: I/System.out(3602): waiting for debugger to settle...07-12 08:25:07.256: I/System.out(3602): debugger has settled (1411)07-12 08:26:55.171: D/ActivityThread(4159): setTargetHeapUtilization:0.2507-12 08:26:55.171: D/ActivityThread(4159): setTargetHeapIdealFree:838860807-12 08:26:55.171: D/ActivityThread(4159): setTargetHeapConcurrentStart:209715207-12 08:26:55.391: W/dalvikvm(4159): threadid=1: thread exiting with uncaught exception (group=0x416cd498)07-12 08:26:55.391: E/AndroidRuntime(4159): FATAL EXCEPTION: main07-12 08:26:55.391: E/AndroidRuntime(4159): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.himi.clock/com.himi.clock.MainActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.himi.clock/com.himi.clock.ClockActivity}; have you declared this activity in your AndroidManifest.xml?07-12 08:26:55.391: E/AndroidRuntime(4159): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2092)07-12 08:26:55.391: E/AndroidRuntime(4159): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2117)07-12 08:26:55.391: E/AndroidRuntime(4159): at android.app.ActivityThread.access$600(ActivityThread.java:140)07-12 08:26:55.391: E/AndroidRuntime(4159): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1213)07-12 08:26:55.391: E/AndroidRuntime(4159): at android.os.Handler.dispatchMessage(Handler.java:99)07-12 08:26:55.391: E/AndroidRuntime(4159): at android.os.Looper.loop(Looper.java:137)07-12 08:26:55.391: E/AndroidRuntime(4159): at android.app.ActivityThread.main(ActivityThread.java:4914)07-12 08:26:55.391: E/AndroidRuntime(4159): at java.lang.reflect.Method.invokeNative(Native Method)07-12 08:26:55.391: E/AndroidRuntime(4159): at java.lang.reflect.Method.invoke(Method.java:511)07-12 08:26:55.391: E/AndroidRuntime(4159): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:808)07-12 08:26:55.391: E/AndroidRuntime(4159): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:575)07-12 08:26:55.391: E/AndroidRuntime(4159): at dalvik.system.NativeStart.main(Native Method)07-12 08:26:55.391: E/AndroidRuntime(4159): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.himi.clock/com.himi.clock.ClockActivity}; have you declared this activity in your AndroidManifest.xml?07-12 08:26:55.391: E/AndroidRuntime(4159): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1541)07-12 08:26:55.391: E/AndroidRuntime(4159): at android.app.ActivityThread.resolveActivityInfo(ActivityThread.java:1903)07-12 08:26:55.391: E/AndroidRuntime(4159): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:285)07-12 08:26:55.391: E/AndroidRuntime(4159): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:694)07-12 08:26:55.391: E/AndroidRuntime(4159): at android.widget.TabHost.setCurrentTab(TabHost.java:358)07-12 08:26:55.391: E/AndroidRuntime(4159): at android.widget.TabHost.addTab(TabHost.java:236)07-12 08:26:55.391: E/AndroidRuntime(4159): at com.himi.clock.MainActivity.addOneTab(MainActivity.java:32)07-12 08:26:55.391: E/AndroidRuntime(4159): at com.himi.clock.MainActivity.onCreate(MainActivity.java:20)07-12 08:26:55.391: E/AndroidRuntime(4159): at android.app.Activity.performCreate(Activity.java:5086)07-12 08:26:55.391: E/AndroidRuntime(4159): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)07-12 08:26:55.391: E/AndroidRuntime(4159): at com.lbe.security.service.core.client.b.x.callActivityOnCreate(Unknown Source)07-12 08:26:55.391: E/AndroidRuntime(4159): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2056)07-12 08:26:55.391: E/AndroidRuntime(4159): ... 11 more07-12 08:34:04.128: D/ActivityThread(6074): setTargetHeapUtilization:0.2507-12 08:34:04.128: D/ActivityThread(6074): setTargetHeapIdealFree:838860807-12 08:34:04.128: D/ActivityThread(6074): setTargetHeapConcurrentStart:209715207-12 08:34:04.379: W/dalvikvm(6074): threadid=1: thread exiting with uncaught exception (group=0x416cd498)07-12 08:34:04.389: E/AndroidRuntime(6074): FATAL EXCEPTION: main07-12 08:34:04.389: E/AndroidRuntime(6074): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.himi.clock/com.himi.clock.MainActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.himi.clock/com.himi.clock.ClockActivity}; have you declared this activity in your AndroidManifest.xml?07-12 08:34:04.389: E/AndroidRuntime(6074): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2092)07-12 08:34:04.389: E/AndroidRuntime(6074): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2117)07-12 08:34:04.389: E/AndroidRuntime(6074): at android.app.ActivityThread.access$600(ActivityThread.java:140)07-12 08:34:04.389: E/AndroidRuntime(6074): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1213)07-12 08:34:04.389: E/AndroidRuntime(6074): at android.os.Handler.dispatchMessage(Handler.java:99)07-12 08:34:04.389: E/AndroidRuntime(6074): at android.os.Looper.loop(Looper.java:137)07-12 08:34:04.389: E/AndroidRuntime(6074): at android.app.ActivityThread.main(ActivityThread.java:4914)07-12 08:34:04.389: E/AndroidRuntime(6074): at java.lang.reflect.Method.invokeNative(Native Method)07-12 08:34:04.389: E/AndroidRuntime(6074): at java.lang.reflect.Method.invoke(Method.java:511)07-12 08:34:04.389: E/AndroidRuntime(6074): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:808)07-12 08:34:04.389: E/AndroidRuntime(6074): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:575)07-12 08:34:04.389: E/AndroidRuntime(6074): at dalvik.system.NativeStart.main(Native Method)07-12 08:34:04.389: E/AndroidRuntime(6074): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.himi.clock/com.himi.clock.ClockActivity}; have you declared this activity in your AndroidManifest.xml?07-12 08:34:04.389: E/AndroidRuntime(6074): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1541)07-12 08:34:04.389: E/AndroidRuntime(6074): at android.app.ActivityThread.resolveActivityInfo(ActivityThread.java:1903)07-12 08:34:04.389: E/AndroidRuntime(6074): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:285)07-12 08:34:04.389: E/AndroidRuntime(6074): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:694)07-12 08:34:04.389: E/AndroidRuntime(6074): at android.widget.TabHost.setCurrentTab(TabHost.java:358)07-12 08:34:04.389: E/AndroidRuntime(6074): at android.widget.TabHost.addTab(TabHost.java:236)07-12 08:34:04.389: E/AndroidRuntime(6074): at com.himi.clock.MainActivity.addOneTab(MainActivity.java:32)07-12 08:34:04.389: E/AndroidRuntime(6074): at com.himi.clock.MainActivity.onCreate(MainActivity.java:20)07-12 08:34:04.389: E/AndroidRuntime(6074): at android.app.Activity.performCreate(Activity.java:5086)07-12 08:34:04.389: E/AndroidRuntime(6074): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)07-12 08:34:04.389: E/AndroidRuntime(6074): at com.lbe.security.service.core.client.b.x.callActivityOnCreate(Unknown Source)07-12 08:34:04.389: E/AndroidRuntime(6074): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2056)07-12 08:34:04.389: E/AndroidRuntime(6074): ... 11 more
仔細閱讀紅色字型處的報錯資訊知道:原來是我編寫的APP中含有的多個Activity,必須要在AndroidManifest.xml中進行聲明,聲明如下:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.himi.clock" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".ClockActivity" /> <activity android:name=".StopwatchActivity" /> <activity android:name=".TimerActivity" /> </application></manifest>
再次載入程式到手機裡面,發現這時候是可以啟動並執行,沒有報錯了
那麼為什麼要這樣在AndroidManifest.xml聲明註冊多個activity???
答:我們知道不同activity代表不同的視窗介面,Android系統只有先註冊了不同的activity,系統內部才能對它操作,比如利用intent操作。
Android(java)學習筆記123:Clock app編寫報錯