Android First应用程序教程

时间:2012-06-26 17:50:13

标签: android android-intent android-emulator

我已根据Android教程创建了一个应用:http://developer.android.com/training/basics/firstapp/index.html

除应用程序名称外,代码完全相同,但应用程序强行关闭。

06-24 16:19:22.279: E/Zygote(33): setreuid() failed. errno: 2 06-24 16:19:33.028: E/Zygote(33): setreuid() failed. errno: 17 06-24 16:19:34.568: E/BatteryService(62): usbOnlinePath not found 06-24 16:19:34.568: E/BatteryService(62): batteryVoltagePath not found 06-24 16:19:34.568: E/BatteryService(62): batteryTemperaturePath not found 06-24 16:19:34.588: E/SurfaceFlinger(62): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake 06-24 16:19:34.698: E/SensorService(62): couldn't open device for module sensors (Invalid argument) 06-24 16:19:39.449: E/System(62): Failure starting core service 06-24 16:19:39.449: E/System(62): java.lang.SecurityException 06-24 16:19:39.449: E/System(62): at android.os.BinderProxy.transact(Native Method) 06-24 16:19:39.449: E/System(62): at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146) 06-24 16:19:39.449: E/System(62): at android.os.ServiceManager.addService(ServiceManager.java:72) 06-24 16:19:39.449: E/System(62): at com.android.server.ServerThread.run(SystemServer.java:206) 06-24 16:19:39.479: E/EventHub(62): could not get driver version for /dev/input/mouse0, Not a typewriter 06-24 16:19:39.479: E/EventHub(62): could not get driver version for /dev/input/mice, Not a typewriter 06-24 16:19:39.808: E/SoundPool(62): error loading /system/media/audio/ui/Effect_Tick.ogg 06-24 16:19:39.808: E/SoundPool(62): error loading /system/media/audio/ui/KeypressStandard.ogg 06-24 16:19:39.808: E/SoundPool(62): error loading /system/media/audio/ui/KeypressSpacebar.ogg 06-24 16:19:39.808: E/SoundPool(62): error loading /system/media/audio/ui/KeypressDelete.ogg 06-24 16:19:39.808: E/SoundPool(62): error loading /system/media/audio/ui/KeypressReturn.ogg 06-24 16:19:39.828: E/UsbObserver(62): java.lang.NullPointerException 06-24 16:19:39.828: E/UsbObserver(62): at com.android.server.UsbObserver.init(UsbObserver.java:131) 06-24 16:19:39.828: E/UsbObserver(62): at com.android.server.UsbObserver.<init>(UsbObserver.java:65) 06-24 16:19:39.828: E/UsbObserver(62): at com.android.server.ServerThread.run(SystemServer.java:402) 06-24 16:19:40.429: E/ThrottleService(62): Could not open GPS configuration file /etc/gps.conf 06-24 16:19:40.958: E/logwrapper(137): executing /system/bin/tc failed: No such file or directory 06-24 16:19:41.069: E/logwrapper(139): executing /system/bin/tc failed: No such file or directory 06-24 16:19:41.129: E/logwrapper(144): executing /system/bin/tc failed: No such file or directory 06-24 16:37:58.420: E/AndroidRuntime(345): FATAL EXCEPTION: main 06-24 16:37:58.420: E/AndroidRuntime(345): java.lang.IllegalStateException: Could not execute method of the activity 06-24 16:37:58.420: E/AndroidRuntime(345): at android.view.View$1.onClick(View.java:2144) 06-24 16:37:58.420: E/AndroidRuntime(345): at android.view.View.performClick(View.java:2485) 06-24 16:37:58.420: E/AndroidRuntime(345): at android.view.View$PerformClick.run(View.java:9080) 06-24 16:37:58.420: E/AndroidRuntime(345): at android.os.Handler.handleCallback(Handler.java:587) 06-24 16:37:58.420: E/AndroidRuntime(345): at android.os.Handler.dispatchMessage(Handler.java:92) 06-24 16:37:58.420: E/AndroidRuntime(345): at android.os.Looper.loop(Looper.java:123) 06-24 16:37:58.420: E/AndroidRuntime(345): at android.app.ActivityThread.main(ActivityThread.java:3683) 06-24 16:37:58.420: E/AndroidRuntime(345): at java.lang.reflect.Method.invokeNative(Native Method) 06-24 16:37:58.420: E/AndroidRuntime(345): at java.lang.reflect.Method.invoke(Method.java:507) 06-24 16:37:58.420: E/AndroidRuntime(345): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 06-24 16:37:58.420: E/AndroidRuntime(345): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 06-24 16:37:58.420: E/AndroidRuntime(345): at dalvik.system.NativeStart.main(Native Method) 06-24 16:37:58.420: E/AndroidRuntime(345): Caused by: java.lang.reflect.InvocationTargetException 06-24 16:37:58.420: E/AndroidRuntime(345): at java.lang.reflect.Method.invokeNative(Native Method) 06-24 16:37:58.420: E/AndroidRuntime(345): at java.lang.reflect.Method.invoke(Method.java:507) 06-24 16:37:58.420: E/AndroidRuntime(345): at android.view.View$1.onClick(View.java:2139) 06-24 16:37:58.420: E/AndroidRuntime(345): ... 11 more 06-24 16:37:58.420: E/AndroidRuntime(345): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.myfirstapp/DisplayMessageActivity.java.DisplayMessageActivity}; have you declared this activity in your AndroidManifest.xml? 06-24 16:37:58.420: E/AndroidRuntime(345): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405) 06-24 16:37:58.420: E/AndroidRuntime(345): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379) 06-24 16:37:58.420: E/AndroidRuntime(345): at android.app.Activity.startActivityForResult(Activity.java:2827) 06-24 16:37:58.420: E/AndroidRuntime(345): at android.app.Activity.startActivity(Activity.java:2933) 06-24 16:37:58.420: E/AndroidRuntime(345): at com.myfirstapp.MyFirstActivity.sendMessage(MyFirstActivity.java:26) 06-24 16:37:58.420: E/AndroidRuntime(345): ... 14 more 06-24 16:38:47.529: E/AndroidRuntime(357): FATAL EXCEPTION: main 06-24 16:38:47.529: E/AndroidRuntime(357): java.lang.IllegalStateException: Could not execute method of the activity 06-24 16:38:47.529: E/AndroidRuntime(357): at android.view.View$1.onClick(View.java:2144) 06-24 16:38:47.529: E/AndroidRuntime(357): at android.view.View.performClick(View.java:2485) 06-24 16:38:47.529: E/AndroidRuntime(357): at android.view.View$PerformClick.run(View.java:9080) 06-24 16:38:47.529: E/AndroidRuntime(357): at android.os.Handler.handleCallback(Handler.java:587) 06-24 16:38:47.529: E/AndroidRuntime(357): at android.os.Handler.dispatchMessage(Handler.java:92) 06-24 16:38:47.529: E/AndroidRuntime(357): at android.os.Looper.loop(Looper.java:123) 06-24 16:38:47.529: E/AndroidRuntime(357): at android.app.ActivityThread.main(ActivityThread.java:3683) 06-24 16:38:47.529: E/AndroidRuntime(357): at java.lang.reflect.Method.invokeNative(Native Method) 06-24 16:38:47.529: E/AndroidRuntime(357): at java.lang.reflect.Method.invoke(Method.java:507) 06-24 16:38:47.529: E/AndroidRuntime(357): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 06-24 16:38:47.529: E/AndroidRuntime(357): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 06-24 16:38:47.529: E/AndroidRuntime(357): at dalvik.system.NativeStart.main(Native Method) 06-24 16:38:47.529: E/AndroidRuntime(357): Caused by: java.lang.reflect.InvocationTargetException 06-24 16:38:47.529: E/AndroidRuntime(357): at java.lang.reflect.Method.invokeNative(Native Method) 06-24 16:38:47.529: E/AndroidRuntime(357): at java.lang.reflect.Method.invoke(Method.java:507) 06-24 16:38:47.529: E/AndroidRuntime(357): at android.view.View$1.onClick(View.java:2139) 06-24 16:38:47.529: E/AndroidRuntime(357): ... 11 more 06-24 16:38:47.529: E/AndroidRuntime(357): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.myfirstapp/DisplayMessageActivity.java.DisplayMessageActivity}; have you declared this activity in your AndroidManifest.xml? 06-24 16:38:47.529: E/AndroidRuntime(357): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405) 06-24 16:38:47.529: E/AndroidRuntime(357): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379) 06-24 16:38:47.529: E/AndroidRuntime(357): at android.app.Activity.startActivityForResult(Activity.java:2827) 06-24 16:38:47.529: E/AndroidRuntime(357): at android.app.Activity.startActivity(Activity.java:2933) 06-24 16:38:47.529: E/AndroidRuntime(357): at com.myfirstapp.MyFirstActivity.sendMessage(MyFirstActivity.java:26) 06-24 16:38:47.529: E/AndroidRuntime(357): ... 14 more 06-24 16:43:20.070: E/AndroidRuntime(385): FATAL EXCEPTION: main 06-24 16:43:20.070: E/AndroidRuntime(385): java.lang.IllegalStateException: Could not execute method of the activity 06-24 16:43:20.070: E/AndroidRuntime(385): at android.view.View$1.onClick(View.java:2144) 06-24 16:43:20.070: E/AndroidRuntime(385): at android.view.View.performClick(View.java:2485) 06-24 16:43:20.070: E/AndroidRuntime(385): at android.view.View$PerformClick.run(View.java:9080) 06-24 16:43:20.070: E/AndroidRuntime(385): at android.os.Handler.handleCallback(Handler.java:587) 06-24 16:43:20.070: E/AndroidRuntime(385): at android.os.Handler.dispatchMessage(Handler.java:92) 06-24 16:43:20.070: E/AndroidRuntime(385): at android.os.Looper.loop(Looper.java:123) 06-24 16:43:20.070: E/AndroidRuntime(385): at android.app.ActivityThread.main(ActivityThread.java:3683) 06-24 16:43:20.070: E/AndroidRuntime(385): at java.lang.reflect.Method.invokeNative(Native Method) 06-24 16:43:20.070: E/AndroidRuntime(385): at java.lang.reflect.Method.invoke(Method.java:507) 06-24 16:43:20.070: E/AndroidRuntime(385): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 06-24 16:43:20.070: E/AndroidRuntime(385): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 06-24 16:43:20.070: E/AndroidRuntime(385): at dalvik.system.NativeStart.main(Native Method) 06-24 16:43:20.070: E/AndroidRuntime(385): Caused by: java.lang.reflect.InvocationTargetException 06-24 16:43:20.070: E/AndroidRuntime(385): at java.lang.reflect.Method.invokeNative(Native Method) 06-24 16:43:20.070: E/AndroidRuntime(385): at java.lang.reflect.Method.invoke(Method.java:507) 06-24 16:43:20.070: E/AndroidRuntime(385): at android.view.View$1.onClick(View.java:2139) 06-24 16:43:20.070: E/AndroidRuntime(385): ... 11 more 06-24 16:43:20.070: E/AndroidRuntime(385): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.myfirstapp/DisplayMessageActivity.java.DisplayMessageActivity}; have you declared this activity in your AndroidManifest.xml? 06-24 16:43:20.070: E/AndroidRuntime(385): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405) 06-24 16:43:20.070: E/AndroidRuntime(385): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379) 06-24 16:43:20.070: E/AndroidRuntime(385): at android.app.Activity.startActivityForResult(Activity.java:2827) 06-24 16:43:20.070: E/AndroidRuntime(385): at android.app.Activity.startActivity(Activity.java:2933) 06-24 16:43:20.070: E/AndroidRuntime(385): at com.myfirstapp.MyFirstActivity.sendMessage(MyFirstActivity.java:26) 06-24 16:43:20.070: E/AndroidRuntime(385): ... 14 more 06-24 16:45:09.099: E/AndroidRuntime(425): FATAL EXCEPTION: main 06-24 16:45:09.099: E/AndroidRuntime(425): java.lang.IllegalStateException: Could not execute method of the activity 06-24 16:45:09.099: E/AndroidRuntime(425): at android.view.View$1.onClick(View.java:2144) 06-24 16:45:09.099: E/AndroidRuntime(425): at android.view.View.performClick(View.java:2485) 06-24 16:45:09.099: E/AndroidRuntime(425): at android.view.View$PerformClick.run(View.java:9080) 06-24 16:45:09.099: E/AndroidRuntime(425): at android.os.Handler.handleCallback(Handler.java:587) 06-24 16:45:09.099: E/AndroidRuntime(425): at android.os.Handler.dispatchMessage(Handler.java:92) 06-24 16:45:09.099: E/AndroidRuntime(425): at android.os.Looper.loop(Looper.java:123) 06-24 16:45:09.099: E/AndroidRuntime(425): at android.app.ActivityThread.main(ActivityThread.java:3683) 06-24 16:45:09.099: E/AndroidRuntime(425): at java.lang.reflect.Method.invokeNative(Native Method) 06-24 16:45:09.099: E/AndroidRuntime(425): at java.lang.reflect.Method.invoke(Method.java:507) 06-24 16:45:09.099: E/AndroidRuntime(425): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 06-24 16:45:09.099: E/AndroidRuntime(425): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 06-24 16:45:09.099: E/AndroidRuntime(425): at dalvik.system.NativeStart.main(Native Method) 06-24 16:45:09.099: E/AndroidRuntime(425): Caused by: java.lang.reflect.InvocationTargetException 06-24 16:45:09.099: E/AndroidRuntime(425): at java.lang.reflect.Method.invokeNative(Native Method) 06-24 16:45:09.099: E/AndroidRuntime(425): at java.lang.reflect.Method.invoke(Method.java:507) 06-24 16:45:09.099: E/AndroidRuntime(425): at android.view.View$1.onClick(View.java:2139) 06-24 16:45:09.099: E/AndroidRuntime(425): ... 11 more 06-24 16:45:09.099: E/AndroidRuntime(425): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.myfirstapp/DisplayMessageActivity.java.DisplayMessageActivity}; have you declared this activity in your AndroidManifest.xml? 06-24 16:45:09.099: E/AndroidRuntime(425): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405) 06-24 16:45:09.099: E/AndroidRuntime(425): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379) 06-24 16:45:09.099: E/AndroidRuntime(425): at android.app.Activity.startActivityForResult(Activity.java:2827) 06-24 16:45:09.099: E/AndroidRuntime(425): at android.app.Activity.startActivity(Activity.java:2933) 06-24 16:45:09.099: E/AndroidRuntime(425): at com.myfirstapp.MyFirstActivity.sendMessage(MyFirstActivity.java:26) 06-24 16:45:09.099: E/AndroidRuntime(425): ... 14 more 06-24 18:20:31.070: E/AndroidRuntime(464): FATAL EXCEPTION: main 06-24 18:20:31.070: E/AndroidRuntime(464): java.lang.IllegalStateException: Could not execute method of the activity 06-24 18:20:31.070: E/AndroidRuntime(464): at android.view.View$1.onClick(View.java:2144) 06-24 18:20:31.070: E/AndroidRuntime(464): at android.view.View.performClick(View.java:2485) 06-24 18:20:31.070: E/AndroidRuntime(464): at android.view.View$PerformClick.run(View.java:9080) 06-24 18:20:31.070: E/AndroidRuntime(464): at android.os.Handler.handleCallback(Handler.java:587) 06-24 18:20:31.070: E/AndroidRuntime(464): at android.os.Handler.dispatchMessage(Handler.java:92) 06-24 18:20:31.070: E/AndroidRuntime(464): at android.os.Looper.loop(Looper.java:123) 06-24 18:20:31.070: E/AndroidRuntime(464): at android.app.ActivityThread.main(ActivityThread.java:3683) 06-24 18:20:31.070: E/AndroidRuntime(464): at java.lang.reflect.Method.invokeNative(Native Method) 06-24 18:20:31.070: E/AndroidRuntime(464): at java.lang.reflect.Method.invoke(Method.java:507) 06-24 18:20:31.070: E/AndroidRuntime(464): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 06-24 18:20:31.070: E/AndroidRuntime(464): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 06-24 18:20:31.070: E/AndroidRuntime(464): at dalvik.system.NativeStart.main(Native Method) 06-24 18:20:31.070: E/AndroidRuntime(464): Caused by: java.lang.reflect.InvocationTargetException 06-24 18:20:31.070: E/AndroidRuntime(464): at java.lang.reflect.Method.invokeNative(Native Method) 06-24 18:20:31.070: E/AndroidRuntime(464): at java.lang.reflect.Method.invoke(Method.java:507) 06-24 18:20:31.070: E/AndroidRuntime(464): at android.view.View$1.onClick(View.java:2139) 06-24 18:20:31.070: E/AndroidRuntime(464): ... 11 more 06-24 18:20:31.070: E/AndroidRuntime(464): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.myfirstapp/DisplayMessageActivity.java.DisplayMessageActivity}; have you declared this activity in your AndroidManifest.xml? 06-24 18:20:31.070: E/AndroidRuntime(464): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405) 06-24 18:20:31.070: E/AndroidRuntime(464): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379) 06-24 18:20:31.070: E/AndroidRuntime(464): at android.app.Activity.startActivityForResult(Activity.java:2827) 06-24 18:20:31.070: E/AndroidRuntime(464): at android.app.Activity.startActivity(Activity.java:2933) 06-24 18:20:31.070: E/AndroidRuntime(464): at com.myfirstapp.MyFirstActivity.sendMessage(MyFirstActivity.java:26) 06-24 18:20:31.070: E/AndroidRuntime(464): ... 14 more 06-24 18:25:12.590: E/AndroidRuntime(477): FATAL EXCEPTION: main 06-24 18:25:12.590: E/AndroidRuntime(477): java.lang.IllegalStateException: Could not execute method of the activity 06-24 18:25:12.590: E/AndroidRuntime(477): at android.view.View$1.onClick(View.java:2144) 06-24 18:25:12.590: E/AndroidRuntime(477): at android.view.View.performClick(View.java:2485) 06-24 18:25:12.590: E/AndroidRuntime(477): at android.view.View$PerformClick.run(View.java:9080) 06-24 18:25:12.590: E/AndroidRuntime(477): at android.os.Handler.handleCallback(Handler.java:587) 06-24 18:25:12.590: E/AndroidRuntime(477): at android.os.Handler.dispatchMessage(Handler.java:92) 06-24 18:25:12.590: E/AndroidRuntime(477): at android.os.Looper.loop(Looper.java:123) 06-24 18:25:12.590: E/AndroidRuntime(477): at android.app.ActivityThread.main(ActivityThread.java:3683) 06-24 18:25:12.590: E/AndroidRuntime(477): at java.lang.reflect.Method.invokeNative(Native Method) 06-24 18:25:12.590: E/AndroidRuntime(477): at java.lang.reflect.Method.invoke(Method.java:507) 06-24 18:25:12.590: E/AndroidRuntime(477): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 06-24 18:25:12.590: E/AndroidRuntime(477): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 06-24 18:25:12.590: E/AndroidRuntime(477): at dalvik.system.NativeStart.main(Native Method) 06-24 18:25:12.590: E/AndroidRuntime(477): Caused by: java.lang.reflect.InvocationTargetException 06-24 18:25:12.590: E/AndroidRuntime(477): at java.lang.reflect.Method.invokeNative(Native Method) 06-24 18:25:12.590: E/AndroidRuntime(477): at java.lang.reflect.Method.invoke(Method.java:507) 06-24 18:25:12.590: E/AndroidRuntime(477): at android.view.View$1.onClick(View.java:2139) 06-24 18:25:12.590: E/AndroidRuntime(477): ... 11 more 06-24 18:25:12.590: E/AndroidRuntime(477): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.myfirstapp/DisplayMessageActivity.java.DisplayMessageActivity}; have you declared this activity in your AndroidManifest.xml? 06-24 18:25:12.590: E/AndroidRuntime(477): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405) 06-24 18:25:12.590: E/AndroidRuntime(477): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379) 06-24 18:25:12.590: E/AndroidRuntime(477): at android.app.Activity.startActivityForResult(Activity.java:2827) 06-24 18:25:12.590: E/AndroidRuntime(477): at android.app.Activity.startActivity(Activity.java:2933) 06-24 18:25:12.590: E/AndroidRuntime(477): at com.myfirstapp.MyFirstActivity.sendMessage(MyFirstActivity.java:26) 06-24 18:25:12.590: E/AndroidRuntime(477): ... 14 more <code>

不确定如何调试此应用。 请建议

由于

SSAMEERR

5 个答案:

答案 0 :(得分:1)

  • 无法找到明确的活动类 {com.myfirstapp / DisplayMessageActivity.java.DisplayMessageActivity}; 你有没有在AndroidManifest.xml中声明这个活动?

将DisplayMessageActivity的条目放入manifest .......

它DisplayMessageActivity是第一个Activity使用intent-filter,其他删除它。

<activity android:name=".DisplayMessageActivity" android:label="Demo App">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

答案 1 :(得分:1)

答案在logcat中:

Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.myfirstapp/DisplayMessageActivity.java.DisplayMessageActivity}; have you declared this activity in your AndroidManifest.xml?

Declare the activity in your manifest就像这样(即将其插入<application></application>标签之间的某处):

<activity android:name=".DisplayMessageActivity" />

这是一个常见的初学者错误...在你习惯它之前至少要多少次这个错误。 :)

答案 2 :(得分:1)

将其作为

添加到DisplayMessageActivity清单中
<application ... >
    <activity android:name=".DisplayMessageActivity" />
    ...
</application>

答案 3 :(得分:0)

确保项目中的其他活动已添加到AndroidManifest.xml

答案 4 :(得分:0)

您必须将您的活动包含在Manifest中,如:

<activity android:name=".MyFirstActivity"
            android:theme="@android:style/Theme.NoTitleBar">

        </activity>