videoview.setVideoUri shows null pointer exception

You should add a contentView on your activity onCreate So change your onCreate Like this:

    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.your_layout_name)  // Add this line, 
        VideoView videoView=findViewById(;
        String path="android.resource://"+getPackageName()+"/"+R.raw.playthis;
        Uri uri=Uri.parse(path);

After that you should check null video path, like

// If path is not null then set it to your videoView.
if(uri.getPath() != null) {

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top