使用以下示例尝试从MP4创建缩略图时,我收到错误消息FATAL EXCEPTION: main Caused by: java.lang.NullPointerException at Home.java:35
:How 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);
}
}
答案 0 :(得分:4)
您没有初始化videoview
。
你可以这样做:
videoview = (ImageView) findViewById(R.id.myImageView)