Eclipse logcat debugging

后端 未结 3 1496
Happy的楠姐
Happy的楠姐 2020-11-28 16:54

I have a beginner question, I want to debug my app and i don\'t know how to use the Logcat properly.

Right now, I am getting this error and i don\'t know what it mea

相关标签:
3条回答
  • 2020-11-28 17:20

    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.

    0 讨论(0)
  • 2020-11-28 17:31

    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..

    0 讨论(0)
  • 2020-11-28 17:34

    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.

    0 讨论(0)
提交回复
热议问题