-3

I'm getting an error stating FATAL EXCEPTION: main Caused by: java.lang.NullPointerException at Home.java:35 when attempting to create a thumbnail from a MP4 using the following example: How to get image from video file

Line 35 is thumb.getWidth(), thumb.getHeight(), matrix, true);

The MP4 URL is valid - so I'm not sure exactly why this is happening.

Source:

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);



    }
}
Community
  • 1
  • 1
user3254794
  • 11
  • 1
  • 4
  • 1
    from your code viewView can only be null, as suggested by eclise and illustrated by the exception. now, you know where the crash is, you know why, and you know which variable is the issue. what is your question ? – njzk2 Jan 31 '14 at 21:51
  • Source updated - I think it should be a valid question now. – user3254794 Jan 31 '14 at 22:25
  • I don't understand...the edit didn't add anything, it just fixed the formatting and removed relevant information. (Note: I didn't vote to close as a dupe, I voted to close as "insufficient information to diagnose the problem") – Adi Inbar Feb 01 '14 at 21:47

1 Answers1

4

You didn't initialize videoview.

You can do that like this:

videoview = (ImageView) findViewById(R.id.myImageView)
Ahmad
  • 69,608
  • 17
  • 111
  • 137