0

I'm inflating layout with VideoView into ViewPager.

Here is code in instantiateItem function:

RelativeLayout v = (RelativeLayout) li.inflate(R.layout.background34, null);

vv = (VideoView)v.findViewById(R.id.videoView);
            Uri video = Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.advetime);
MediaController mc = new MediaController(context);
mc.setAnchorView(vv);
mc.setMediaPlayer(vv);
vv.setMediaController(mc);
mc.show(0);
vv.setVideoURI(video);
vv.start();

my app crashes at line mc.show(0) with error:

E/AndroidRuntime(24284): FATAL EXCEPTION: main
E/AndroidRuntime(24284): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?

What is the problem? Help me please.

TrueCH
  • 501
  • 1
  • 6
  • 18
  • when `mc.show(0) ... vv.start()` is called view `v` is not connected to any Window ... you need to choose better place (not `instantiateItem`) to start video – Selvin Aug 22 '13 at 11:31
  • I placed button in view that I'm inflating in `instantiate` func. `OnClickListener` of this button now do `vv = (VideoView)v.findViewById(R.id.videoView);` `Uri video = Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.advetime);` `MediaController mc = new MediaController(context);` `mc.setAnchorView(vv);` `mc.setMediaPlayer(vv);` `vv.setMediaController(mc);` `mc.show(0);` `vv.setVideoURI(video);` `vv.start();` I'm still recieving this error – TrueCH Aug 23 '13 at 04:49

0 Answers0