当我尝试运行此代码时,它会强制关闭。我提前道歉,因为我是java的菜鸟。
package com.MrNom;
import android.app.Activity;
import android.os.Bundle;
public class NomActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
在强行关闭之前,它在LogCat中是红色的。
07-29 18:59:40.626: ERROR/AndroidRuntime(347): FATAL EXCEPTION: main
07-29 18:59:40.626: ERROR/AndroidRuntime(347): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.MrNom/com.MrNom.Mr.NomActivity}: java.lang.ClassNotFoundException: com.MrNom.Mr.NomActivity in loader dalvik.system.PathClassLoader[/data/app/com.MrNom-1.apk]
07-29 18:59:40.626: ERROR/AndroidRuntime(347): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
07-29 18:59:40.626: ERROR/AndroidRuntime(347): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-29 18:59:40.626: ERROR/AndroidRuntime(347): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-29 18:59:40.626: ERROR/AndroidRuntime(347): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-29 18:59:40.626: ERROR/AndroidRuntime(347): at android.os.Handler.dispatchMessage(Handler.java:99)
07-29 18:59:40.626: ERROR/AndroidRuntime(347): at android.os.Looper.loop(Looper.java:123)
07-29 18:59:40.626: ERROR/AndroidRuntime(347): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-29 18:59:40.626: ERROR/AndroidRuntime(347): at java.lang.reflect.Method.invokeNative(Native Method)
07-29 18:59:40.626: ERROR/AndroidRuntime(347): at java.lang.reflect.Method.invoke(Method.java:521)
07-29 18:59:40.626: ERROR/AndroidRuntime(347): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-29 18:59:40.626: ERROR/AndroidRuntime(347): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-29 18:59:40.626: ERROR/AndroidRuntime(347): at dalvik.system.NativeStart.main(Native Method)
07-29 18:59:40.626: ERROR/AndroidRuntime(347): Caused by: java.lang.ClassNotFoundException: com.MrNom.Mr.NomActivity in loader dalvik.system.PathClassLoader[/data/app/com.MrNom-1.apk]
07-29 18:59:40.626: ERROR/AndroidRuntime(347): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
07-29 18:59:40.626: ERROR/AndroidRuntime(347): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
07-29 18:59:40.626: ERROR/AndroidRuntime(347): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
07-29 18:59:40.626: ERROR/AndroidRuntime(347): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
07-29 18:59:40.626: ERROR/AndroidRuntime(347): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
答案 0 :(得分:2)
在AndroidManifest.xml
中,找到您声明该活动的位置,并将其名称属性从“com.MrNom.Mr.NomActivity”更改为“com.MrNom.NomActivity”。
从活动类中可以看出,它位于“com.MrNom”包中,而不是“com.MrNom.Mr”
答案 1 :(得分:0)
对我而言,似乎你以某种方式搞砸了名称空间 - 在例外情况下它表示它试图创建未找到的com.MrNom.Mr.NomActivity
...正确的类将是(只是一个猜测){{1你在运行时遇到的地方必须有com.MrNom.NomActivity
- 你没有显示足够的代码来解决这个问题......