致命异常:主要原因:Home.java上的java.lang.NullPointerException:35

时间:2014-01-31 21:49:39

标签: java android nullpointerexception fatal-error forceclose

使用以下示例尝试从MP4创建缩略图时,我收到错误消息FATAL EXCEPTION: main Caused by: java.lang.NullPointerException at Home.java:35How to get image from video file

第35行是thumb.getWidth(), thumb.getHeight(), matrix, true);

MP4网址有效 - 所以我不确定为什么会发生这种情况。

来源:

public class Home extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);


        ImageView videoview;
        videoview = (ImageView) findViewById(R.id.myImageView);
         Bitmap thumb = ThumbnailUtils.createVideoThumbnail("http://techslides.com/demos/sample-videos/small.mp4",   MediaStore.Images.Thumbnails.MINI_KIND);
         Matrix matrix = new Matrix();
         Bitmap bmThumbnail = Bitmap.createBitmap(thumb, 0, 0,
         thumb.getWidth(), thumb.getHeight(), matrix, true);
         videoview.setImageBitmap(bmThumbnail);



    }
}

1 个答案:

答案 0 :(得分:4)

您没有初始化videoview

你可以这样做:

videoview = (ImageView) findViewById(R.id.myImageView)