Eclipse logcat debugging

After you see

FATAL EXCEPTION: main

you will see the problem, here a NPE

09-23 11:27:55.968: E/AndroidRuntime(807): java.lang.NullPointerException

then you find the first line that references your app. Here it is the following line

at com.uniqueapps.runner.Start.onClick(Start.java:49)

This says that in Start.java something is null in onClick() at line 49. So you go to that line and see what could be null…like a variable that tries to access a method such as setText(), getText(), or any Android or user defined method. Sometimes it is simple why it is null and sometimes you have to trace back further to see what makes it null.

Edit

If a variable is null it is because it hasn’t been initialized properly, or at all. So maybe you have a variable TextView tv; but you never gave it a value by doing something like

 tv = (TextView) findViewById(R.id.myTV);

if you try to do something like tv.setText("Some Text"); you will get a NPE because you didn’t initialize it with something like the above line of code. Or maybe you tried to initialize it and used the wrong id like one from a different layout. This will return null and create a NPE in the same way. This can be on any variable that you try to call a method on.

Leave a Comment