Eclipse logcat debugging

淺唱寂寞╮ 提交于 2019-11-26 23:12:38

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.

It says it's NullPointerException at 49 th line on Start.java file.

Logcat allows you to filter you your all logs from left pan. Which is the best thing over there.

you can try this tips to use logcat..

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    System.out.println("1. Before Declare");

    textView = (TextView) findViewById(R.id.textView);

    System.out.println("2. After Declare"); 

}

See result on logcat, then you can see your step..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!