Question

I have made made 2 xml files that have identical widgets. First file (main) the widgets are arranged in a Relative layout and the second (testgrid2) the widgets are in a TableLayout. The first xml file works fine and app runs. The second xml file I created so I can test before I replace it with the original (main). when I test the second (testgrids)it crashes but I cannot understand the log cat errors it is generating.

The only changes I make to test is in the set Content view.

setContentView(R.layout.main);

and testing

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
Was it helpful?

Solution

Here:

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

So fix your NPE in SimpleRGB_Main.java line 1429

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top