Android Studio记录一个错误:java.lang.NullPointerException: Attempt to invoke virtual method ‘void android.

这里写目录标题

  • 错误
  • 解决

错误

java.lang.NullPointerException: Attempt to invoke virtual method ‘void android.widget.TextView.setText(java.lang.CharSequence)’ on a null object reference
Android Studio记录一个错误:java.lang.NullPointerException: Attempt to invoke virtual method ‘void android._第1张图片

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.dialogdownapplication, PID: 9769
    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
        at com.example.dialogdownapplication.DialogDown.setProgress(DialogDown.java:44)
        at com.example.dialogdownapplication.MainActivity$1.handleMessage(MainActivity.java:27)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6121)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:892)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)

Android Studio记录一个错误:java.lang.NullPointerException: Attempt to invoke virtual method ‘void android._第2张图片

解决

在这里插入图片描述

  • 空指针异常
    可以找找:id的定义,对象/实例的初始化,事件的监听部分
  • 点报错位置找到对应控件位置
    Android Studio记录一个错误:java.lang.NullPointerException: Attempt to invoke virtual method ‘void android._第3张图片
  • 检查id、定义、事件
    Android Studio记录一个错误:java.lang.NullPointerException: Attempt to invoke virtual method ‘void android._第4张图片
    少了view
    因为并不是在Activity里面,所以修改如下
tvDialog = view.findViewById(R.id.tvDialog);
pbDialog = view.findViewById(R.id.pbDialog);

重新运行无报错

你可能感兴趣的:(记录错误,Android,android,android,studio)