小编典典

java.lang.RuntimeException:无法实例化活动 ComponentInfo

all

我试图运行示例代码在 android 1.5 模拟器中启动应用程序时,我收到了这些错误.. 任何人都有一些提示..?

来自 LogCat 的错误:

01-13 02:28:08.392: ERROR/AndroidRuntime(2888): FATAL EXCEPTION: main
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.s.android.test/com.s.android.test.MainActivity}: java.lang.ClassNotFoundException: com.s.android.test.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.s.android.test-2.apk]
01-13 02:28:08.392: ERROR/AndroidRuntime(2888):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1544)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888):     at android.os.Looper.loop(Looper.java:123)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888):     at android.app.ActivityThread.main(ActivityThread.java:3647)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888):     at java.lang.reflect.Method.invokeNative(Native Method)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888):     at java.lang.reflect.Method.invoke(Method.java:507)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888):     at dalvik.system.NativeStart.main(Native Method)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888): Caused by: java.lang.ClassNotFoundException: com.s.android.test.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.s.android.test-2.apk]
01-13 02:28:08.392: ERROR/AndroidRuntime(2888):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888):     at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1536)
01-13 02:28:08.392: ERROR/AndroidRuntime(2888):     ... 11 more
01-13 02:28:08.407: WARN/ActivityManager(112):   Force finishing activity com.s.android.test/.MainActivity

编辑 这个错误发生在大多数初学者身上,问题是您必须在清单文件中添加所有活动。


阅读 73

收藏
2022-08-19

共1个答案

小编典典

这是您的意图的问题。

Activity在您的 AndroidManifest.xml.

当你想创建一个新活动时,你应该在你的AndroidManifest.xml.

2022-08-19