码迷,mamicode.com
首页 > 移动开发 > 详细

Android(java)学习笔记123:Clock app编写报错

时间:2015-07-12 09:35:18      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

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=ReferenceQueueDaemon
07-12 08:25:03.582: E/dalvikvm(3602): threadid=6: calling run(),name=ReferenceQueueDaemon
07-12 08:25:03.582: E/dalvikvm(3602): threadid=7: created from interp,name=FinalizerDaemon
07-12 08:25:03.582: E/dalvikvm(3602): threadid=7: calling run(),name=FinalizerDaemon
07-12 08:25:03.592: E/dalvikvm(3602): threadid=8: created from interp,name=FinalizerWatchdogDaemon
07-12 08:25:03.592: E/dalvikvm(3602): threadid=8: calling run(),name=FinalizerWatchdogDaemon
07-12 08:25:03.642: D/ActivityThread(3602): setTargetHeapUtilization:0.25
07-12 08:25:03.642: D/ActivityThread(3602): setTargetHeapIdealFree:8388608
07-12 08:25:03.642: D/ActivityThread(3602): setTargetHeapConcurrentStart:2097152
07-12 08:25:03.662: I/System.out(3602): Sending WAIT chunk
07-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 connected
07-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.25
07-12 08:26:55.171: D/ActivityThread(4159): setTargetHeapIdealFree:8388608
07-12 08:26:55.171: D/ActivityThread(4159): setTargetHeapConcurrentStart:2097152
07-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: main
07-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 more
07-12 08:34:04.128: D/ActivityThread(6074): setTargetHeapUtilization:0.25
07-12 08:34:04.128: D/ActivityThread(6074): setTargetHeapIdealFree:8388608
07-12 08:34:04.128: D/ActivityThread(6074): setTargetHeapConcurrentStart:2097152
07-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: main
07-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编写报错

标签:

原文地址:http://www.cnblogs.com/hebao0514/p/4640494.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!