How to troubleshoot NullPointerException?

前端 未结 3 450
太阳男子
太阳男子 2020-12-22 11:40

The below program throws a NullPointerException. In Log cat it shows:

01-09 20:40:34.366: D/RemoteIt(2809): java.lang.NullPointerException

3条回答
  •  没有蜡笔的小新
    2020-12-22 12:31

    Your question, as stated, asks about how to troubleshoot this.

    You need to figure out what's null on the line throwing the Exception. To do that, you take a look at the stack trace to see which line is causing the problem. Then you either step through your program with a debugger (or a piece of paper and a pencil) or just add print statements to figure out which variable is null.

    When you know which variable is null, you can trace back through the program to figure out why it's null. When you know why it's null, you can fix your problem.

提交回复
热议问题