sky_rab_bit
sky_rab_bit
采纳率100%
2020-05-14 21:09

Attempt to read from field 'android.widget.ImageView com.example.smartdoor.ui.SmartDoorActivity.video' on a null object reference。

10

在android开发中使用ImageView实现视频显示时出现如下报错:

java.lang.NullPointerException: Attempt to read from field 'android.widget.ImageView com.example.smartdoor.ui.SmartDoorActivity.video' on a null object reference
        at com.example.smartdoor.ui.SmartDoorActivity.access$500(SmartDoorActivity.java:49)
        at com.example.smartdoor.ui.SmartDoorActivity$6.handleMessage(SmartDoorActivity.java:353)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:213)
        at android.app.ActivityThread.main(ActivityThread.java:8169)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)

搜索问题后仍无法解决,希望有大佬能够解惑。
出错代码如下:

public static Handler updateUIHandler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case 1:
                    Log.e("SmartDoorActivity", "handleMessage: 接收视频帧");
                    Log.e("SmartDoorActivity", msg.obj.toString());
                    ((SmartDoorActivity)context).video.setImageBitmap((Bitmap)msg.obj);
                default:
                    break;
            }
        }
    };

在这bao'c

((SmartDoorActivity)context).video.setImageBitmap((Bitmap)msg.obj);
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • SkyDream999 Android研习社 1年前

    根据错误信息提示video控件没有实例化,为Null,所以也就找不到setImageBitmap().
    请检查video实例化时机。

    java.lang.NullPointerException: Attempt to read from field 'android.widget.ImageView com.example.smartdoor.ui.SmartDoorActivity.video' on a null object reference
    
    点赞 评论 复制链接分享