2014-01-05 97 views
0

我已經制作了2個具有相同小部件的xml文件。第一個文件(主)部件以相對佈局排列,第二個(testgrid2)部件位於TableLayout中。第一個xml文件工作正常,應用程序運行。我創建的第二個xml文件,所以我可以在將其替換爲原始(main)之前進行測試。當我測試第二個(testgrids)時,它崩潰了,但我無法理解它生成的日誌貓錯誤。需要登錄貓錯誤的幫助

我測試的唯一更改是在設置的內容視圖中。

setContentView(R.layout.main); 

和測試

setContentView(R.layout.testgrid2); 

logcat的

01-05 13:14:38.790: D/dalvikvm(8152): GC_FOR_ALLOC freed 63K, 1% free 8906K/8992K, paused 16ms, total 16ms 
01-05 13:14:38.790: I/dalvikvm-heap(8152): Grow heap (frag case) to 9.428MB for 746512-byte allocation 
01-05 13:14:38.810: D/dalvikvm(8152): GC_FOR_ALLOC freed <1K, 1% free 9635K/9724K, paused 15ms, total 15ms 
01-05 13:14:38.830: D/dalvikvm(8152): GC_FOR_ALLOC freed <1K, 1% free 9635K/9724K, paused 11ms, total 11ms 
01-05 13:14:38.840: I/dalvikvm-heap(8152): Grow heap (frag case) to 12.276MB for 2986000-byte allocation 
01-05 13:14:38.850: D/dalvikvm(8152): GC_FOR_ALLOC freed 0K, 1% free 12551K/12644K, paused 11ms, total 11ms 
01-05 13:14:38.931: D/TAG(8152): Size Pre 600 
01-05 13:14:38.941: D/TAG(8152): File SET 600 
01-05 13:14:38.941: D/TAG(8152): BT true 
01-05 13:14:38.941: D/TAG(8152): CON true 
01-05 13:14:38.941: W/BluetoothAdapter(8152): getBluetoothService() called with no BluetoothManagerCallback 
01-05 13:14:38.941: D/BluetoothSocket(8152): connect(), SocketState: INIT, mPfd: {ParcelFileDescriptor: FileDescriptor[41]} 
01-05 13:14:39.411: D/AndroidRuntime(8152): Shutting down VM 
01-05 13:14:39.411: W/dalvikvm(8152): threadid=1: thread exiting with uncaught exception (group=0x4159a700) 
01-05 13:14:39.421: E/AndroidRuntime(8152): FATAL EXCEPTION: main 
01-05 13:14:39.421: E/AndroidRuntime(8152): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.simplergb/com.example.simplergb.SimpleRGB_Main}: java.lang.NullPointerException 
01-05 13:14:39.421: E/AndroidRuntime(8152):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211) 
01-05 13:14:39.421: E/AndroidRuntime(8152):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261) 
01-05 13:14:39.421: E/AndroidRuntime(8152):  at android.app.ActivityThread.access$600(ActivityThread.java:141) 
01-05 13:14:39.421: E/AndroidRuntime(8152):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) 
01-05 13:14:39.421: E/AndroidRuntime(8152):  at android.os.Handler.dispatchMessage(Handler.java:99) 
01-05 13:14:39.421: E/AndroidRuntime(8152):  at android.os.Looper.loop(Looper.java:137) 
01-05 13:14:39.421: E/AndroidRuntime(8152):  at android.app.ActivityThread.main(ActivityThread.java:5103) 
01-05 13:14:39.421: E/AndroidRuntime(8152):  at java.lang.reflect.Method.invokeNative(Native Method) 
01-05 13:14:39.421: E/AndroidRuntime(8152):  at java.lang.reflect.Method.invoke(Method.java:525) 
01-05 13:14:39.421: E/AndroidRuntime(8152):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
01-05 13:14:39.421: E/AndroidRuntime(8152):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
01-05 13:14:39.421: E/AndroidRuntime(8152):  at dalvik.system.NativeStart.main(Native Method) 
01-05 13:14:39.421: E/AndroidRuntime(8152): Caused by: java.lang.NullPointerException 
01-05 13:14:39.421: E/AndroidRuntime(8152):  at com.example.simplergb.SimpleRGB_Main.onCreate(SimpleRGB_Main.java:1429) 
01-05 13:14:39.421: E/AndroidRuntime(8152):  at android.app.Activity.performCreate(Activity.java:5133) 
01-05 13:14:39.421: E/AndroidRuntime(8152):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
01-05 13:14:39.421: E/AndroidRuntime(8152):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175) 
01-05 13:14:39.421: E/AndroidRuntime(8152):  ... 11 more 

回答

3

這裏:

Caused by: java.lang.NullPointerException 
    at com.example.simplergb.SimpleRGB_Main.onCreate(SimpleRGB_Main.java:1429) 

所以解決您的NPE在SimpleRGB_Main.java線1429

+3

我敢打賭,你可以寫腳本來回答這樣的問題 – marcinj

+0

謝謝我在代碼中輸入了一個類型。現在工作正常。 ++ – Bobby