(VideoView)findViewById(R.id.videoview1)NullPointerException

时间:2014-08-14 09:19:03

标签: java android android-videoview

我试图在对话框中显示视频但是找不到VideoView,尽管id是正确的。我在这一行得到一个NullPointerException:

VideoView vv = (VideoView) findViewById(R.id.videoview1);

这是我的代码:

                Dialog dialog2 = new Dialog(getContext(),
                    android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
            dialog2.setContentView(R.layout.video);

            VideoView vv = (VideoView) findViewById(R.id.videoview1);
            String uri = "android.resource://" + theGameActivity.getPackageName() +"/"+R.raw.video6;
dialog2.show();
            vv.start();

3 个答案:

答案 0 :(得分:2)

试试这个..

改变这个..

VideoView vv = (VideoView) findViewById(R.id.videoview1);

VideoView vv = (VideoView) dialog2.findViewById(R.id.videoview1);

因为View必须引用Dialog

答案 1 :(得分:1)

更改

VideoView vv = (VideoView)findViewById(R.id.videoview1);

VideoView vv = (VideoView)dialog2.findViewById(R.id.videoview1);

因为videoview1R.layout.video的一部分且dialog2视图布局为R.layout.video

答案 2 :(得分:0)

VideoView vv = (VideoView) dialog2.findViewById(R.id.videoview1);

您需要使用对话框对象。说明者获取视频视图ID