我试图在对话框中显示视频但是找不到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();
答案 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);
因为videoview1
是R.layout.video
的一部分且dialog2
视图布局为R.layout.video
答案 2 :(得分:0)
VideoView vv = (VideoView) dialog2.findViewById(R.id.videoview1);
您需要使用对话框对象。说明者获取视频视图ID