2012-08-28 48 views
1

重命名我的主類爲「主」和我的主要xml爲「主」後我可以啓動我的應用程序。 我不斷收到這樣的logcat:重命名主活動後的錯誤

08-28 21:46:27.563: D/AndroidRuntime(264): Shutting down VM 
08-28 21:46:27.563: W/dalvikvm(264): threadid=3: thread exiting with uncaught exception (group=0x4001b188) 
08-28 21:46:27.563: E/AndroidRuntime(264): Uncaught handler: thread main exiting due to uncaught exception 
08-28 21:46:27.623: E/AndroidRuntime(264): java.lang.RuntimeException: Unable to start activity ComponentInfo{noc.support/noc.support.Main}: java.lang.NullPointerException 
08-28 21:46:27.623: E/AndroidRuntime(264): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496) 
08-28 21:46:27.623: E/AndroidRuntime(264): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512) 
08-28 21:46:27.623: E/AndroidRuntime(264): at android.app.ActivityThread.access$2200(ActivityThread.java:119) 
08-28 21:46:27.623: E/AndroidRuntime(264): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863) 
08-28 21:46:27.623: E/AndroidRuntime(264): at android.os.Handler.dispatchMessage(Handler.java:99) 
08-28 21:46:27.623: E/AndroidRuntime(264): at android.os.Looper.loop(Looper.java:123) 
08-28 21:46:27.623: E/AndroidRuntime(264): at android.app.ActivityThread.main(ActivityThread.java:4363) 
08-28 21:46:27.623: E/AndroidRuntime(264): at java.lang.reflect.Method.invokeNative(Native Method) 
08-28 21:46:27.623: E/AndroidRuntime(264): at java.lang.reflect.Method.invoke(Method.java:521) 
08-28 21:46:27.623: E/AndroidRuntime(264): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 
08-28 21:46:27.623: E/AndroidRuntime(264): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
08-28 21:46:27.623: E/AndroidRuntime(264): at dalvik.system.NativeStart.main(Native Method) 
08-28 21:46:27.623: E/AndroidRuntime(264): Caused by: java.lang.NullPointerException 
08-28 21:46:27.623: E/AndroidRuntime(264): at noc.support.Main.onCreate(Main.java:116) 
08-28 21:46:27.623: E/AndroidRuntime(264): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
08-28 21:46:27.623: E/AndroidRuntime(264): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459) 
08-28 21:46:27.623: E/AndroidRuntime(264): ... 11 more 
08-28 21:46:27.653: I/dalvikvm(264): threadid=7: reacting to signal 3 
08-28 21:46:27.663: I/dalvikvm(264): Wrote stack trace to '/data/anr/traces.txt' 
08-28 21:47:07.853: I/Process(264): Sending signal. PID: 264 SIG: 9 

清單:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="noc.support" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk android:minSdkVersion="7" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 


    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" android:debuggable="true"> 

     <service android:name=".BootListnerService" android:label="Boot Service"> 
      <intent-filter> 
       <action android:name="noc.support.BootListnerService" /> 
      </intent-filter> 
     </service> 

     <receiver 
      android:name=".BootListnerServiceReceiver" 
      android:enabled="true" 
      android:exported="true" 
      android:label="BootListnerServiceReceiver"> 
      <intent-filter> 
       <action android:name="android.intent.action.BOOT_COMPLETED" /> 
      </intent-filter> 
     </receiver> 


     <activity 
      android:name=".Main" 
      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=".Register" android:label="Register"></activity> 

     <activity android:name=".Settings" android:label="Settings"></activity> 

     <activity android:name=".ServersStatus" android:label="Servers Status"></activity> 

    </application> 

</manifest> 

,這是main.xml中:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/emailLable" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/textView1" 
     android:layout_marginTop="40dp" 
     android:text="Email:" 
     android:textAppearance="?android:attr/textAppearanceMedium" android:layout_marginLeft="5dp"/> 

    <EditText 
     android:id="@+id/emailField" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:ems="10" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" 
     android:inputType="textEmailAddress" /> 

    <TextView 
     android:id="@+id/passwordLable" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/editText1" 
     android:layout_marginTop="36dp" 
     android:text="Password:" 
     android:textAppearance="?android:attr/textAppearanceMedium" android:layout_marginLeft="5dp"/> 


    <EditText 
     android:id="@+id/passwordField" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:inputType="textPassword" 
     android:layout_marginLeft="5dp" android:layout_marginRight="5dp"/> 

    <CheckBox 
     android:id="@+id/rememberEmailPasswordCheckBox" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Remember my email &amp; password" /> 

    <CheckBox 
     android:id="@+id/loginAutomaticallyCheckBox" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Login automatically" /> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:paddingLeft="5dp" android:paddingRight="5dp" android:layout_marginTop="40dp"> 


     <Button 
      android:id="@+id/addButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1.05" 
      android:text="Add" /> 




     <Button 
      android:id="@+id/refreshButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.86" 
      android:text="Refresh" /> 

    </LinearLayout> 

</LinearLayout> 

我到底做錯了什麼?

沒有人有任何想法。

我GOOGLE了它,但我找不到修復。

當我更改「setContentView(R.layout.main);」到任何其他佈局它的工作fin,但我需要這個類以main.xml開始

+0

您可以發佈更多行logcat異常?特別是_caused by_行。例外是NPE,而不是ResourceNotFound,找不到活動,以及在未正確清理的項目中常見的其他問題。 –

+0

我剛剛做了:)) – Waqleh

回答

0

我固定它通過創建一個新的項目,我的所有文件複製到該項目,但我並沒有取代我複製了主類或佈局,而不是貼類這兩個的內部代碼,但保留班級名稱。這種方式類名是正確的。

+0

我不知道是否有更好的解決方案,但它做到了訣竅 – Waqleh

1

它似乎仍在嘗試啓動活動「ComponentInfo」。如果您更改了所有文件,但沒有更改軟件包名稱,那麼您可能將舊應用程序安裝在舊應用程序之上,而舊啓動程序指向舊活動,舊活動不再存在。

總之:嘗試刪除舊的應用程序並重新安裝。

0

Main.java(您的活動)的第116行有NullPointerException。應該很容易找到自己,或者在這裏發佈Main.java的代碼。

08-28 21:46:27.623: E/AndroidRuntime(264): Caused by: java.lang.NullPointerException 
08-28 21:46:27.623: E/AndroidRuntime(264): at noc.support.Main.onCreate(Main.java:116)