视频播放器工作室mp4

时间:2017-11-15 09:47:21

标签: java android video nullpointerexception android-videoview

我想在对话框窗口中播放视频,但它不起作用。视频而不是“原始”目录。我不知道我哪里错了。你能帮我吗? 有代码

ImageButton video_player = (ImageButton) findViewById(R.id.img_btt_on_ear_watch);
        video_player.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final Dialog dialog = new Dialog(context);
                dialog.setContentView(R.layout.layout_video_player);

                String filePlace = "android.resource://" + getPackageName() + "/" + R.raw.grado_video_cuffie_making;
                VideoView videoV = (VideoView) findViewById(R.id.vv_video_player);
                Uri videoURI = Uri.parse((String) filePlace);
                videoV.setVideoURI(videoURI); //this is the 128 raw
                videoV.setMediaController(new MediaController(context));
                videoV.start();

                ImageButton dialogButton = (ImageButton) dialog.findViewById(R.id.img_btt_vv_close);
                // if button is clicked, close the custom dialog
                dialogButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                    }
                });

                dialog.show();

            }
        });

有Logcat

11-15 10:40:50.666 3893-3893/com.huawei.headphones.huaweimusic E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                 Process: com.huawei.headphones.huaweimusic, PID: 3893
                                                                                 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.VideoView.setVideoURI(android.net.Uri)' on a null object reference
                                                                                     at com.huawei.headphones.huaweimusic.Activity_Cuffia1$1.onClick(Activity_Cuffia1.java:128)
                                                                                     at android.view.View.performClick(View.java:5610)
                                                                                     at android.view.View$PerformClick.run(View.java:22265)
                                                                                     at android.os.Handler.handleCallback(Handler.java:751)
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                     at android.os.Looper.loop(Looper.java:154)
                                                                                     at android.app.ActivityThread.main(ActivityThread.java:6077)
                                                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
                                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

1 个答案:

答案 0 :(得分:1)

使用此

 VideoView videoV = (VideoView) dialog.findViewById(R.id.vv_video_player);

这是

的内容
VideoView videoV = (VideoView) findViewById(R.id.vv_video_player);