2011-07-29 57 views
0

當我嘗試運行此代碼時,它強制關閉。我提前道歉,因爲我是java的noob。每次嘗試運行時,應用程序都會保持關閉狀態。需要幫助。

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) 

回答

2

在你的AndroidManifest.xml中,找到你聲明那個活動的地方,並將它的name屬性從「com.MrNom。 Mr.NomActivity「改爲」com.MrNom.NomActivity「。

你可以從你的活動類看,它在包「com.MrNom」,而不是「com.MrNom.Mr」

0

我看來,你莫名其妙地搞砸了的命名空間 - 在異常它說,它試圖創建com.MrNom.Mr.NomActivity未發現......正確的類將是(只是猜測)com.MrNom.NomActivity - 某處你使運行時相當於那裏必須有Mr. - 你沒有顯示足夠的代碼來解決這個問題......

+0

你需要的清單文件或XML? –

+0

不確定...也許你可以在項目中搜索「Mr.」看看發生了什麼? – Yahia

+0

恩是有沒有像真正的搜索或只是自己看看? –

相關問題