3

The way the app works is that I have a list of videos. The video view will play the videos and the user can swipe left or right to move from video to video.

The app works bug-free in all other devices I have tested on. (Samsung Galaxy Tab 7, Samsung Galaxy Player, Acer Iconia A500, Nook Color, LG Optimus, Kindle Fire)

Then I tested on the Nook Tablet. I am getting a NullPointerException. This occurs when I swipe in one direction (vid1 > vid2), then swipe back the other direction (vid2 > vid1).

Here is the section of the code that crashed:

  private void playVideo(ViewFlipper flipper){

      LinearLayout flipperchild = (LinearLayout) flipper.getCurrentView();
      VideoView video = (VideoView) flipperchild.getChildAt(0);

      if(preVideoView != null){
       preVideoView.stopPlayback();       
       preVideoView.setVisibility(View.INVISIBLE);
      }

              // Current Video        
      nextVideoView = video;

              // Current Video for pausing
      pauseVideoView = nextVideoView;

      nextVideoView.setVisibility(View.VISIBLE);  
      nextVideoView.requestFocus();
      nextVideoView.start();

              // Stores the current video, so when I change videos this
              // becomes the previous video
      preVideoView = nextVideoView;
      isPlaying = true;
      nextVideoView.setOnTouchListener(videoViewTouch);       
   }

Here is the log I took:

E/AndroidRuntime(27744): FATAL EXCEPTION: main
E/AndroidRuntime(27744): java.lang.NullPointerException
E/AndroidRuntime(27744):    at android.widget.VideoView.openVideo(VideoView.java:330)
E/AndroidRuntime(27744):    at android.widget.VideoView.access$2600(VideoView.java:60)
E/AndroidRuntime(27744):    at android.widget.VideoView$6.surfaceCreated(VideoView.java:604)
E/AndroidRuntime(27744):    at android.view.SurfaceView.updateWindow(SurfaceView.java:547)
E/AndroidRuntime(27744):    at android.view.SurfaceView.setVisibility(SurfaceView.java:221)
E/AndroidRuntime(27744):    at com.selectsoft.gymnasticskids.VideoChapter.playVideo(VideoChapter.java:407)
E/AndroidRuntime(27744):    at com.selectsoft.gymnasticskids.VideoChapter.access$2(VideoChapter.java:397)
E/AndroidRuntime(27744):    at com.selectsoft.gymnasticskids.VideoChapter$OnTouchViewFlipper.onTouch(VideoChapter.java:376)
E/AndroidRuntime(27744):    at android.view.View.dispatchTouchEvent(View.java:3882)
E/AndroidRuntime(27744):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:914)
E/AndroidRuntime(27744):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
E/AndroidRuntime(27744):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
E/AndroidRuntime(27744):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
E/AndroidRuntime(27744):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
E/AndroidRuntime(27744):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
E/AndroidRuntime(27744):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
E/AndroidRuntime(27744):    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1852)
E/AndroidRuntime(27744):    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1271)
E/AndroidRuntime(27744):    at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
E/AndroidRuntime(27744):    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1836)
E/AndroidRuntime(27744):    at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2198)
E/AndroidRuntime(27744):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1882)
E/AndroidRuntime(27744):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(27744):    at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime(27744):    at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime(27744):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(27744):    at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(27744):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime(27744):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime(27744):    at dalvik.system.NativeStart.main(Native Method)

I am not sure what's causing the null pointer, but I have tried using both

setContentView(); 
VideoView video = (VideoView) findViewById(R.id.chapterVideoView);

But they didn't work out. At this point I am pretty stumped, and would like some help.

Regards,

Jaime

Jaime
  • 31
  • 2
  • I'd recommend replacing the assignments all over the place with the following line, just to make clear what is going on: `nextVideoView = pauseVideoView = preVideoView = video;`. But I can't imagine that this would actually help the NPE. – sarnold Dec 16 '11 at 00:30
  • Yeah it was getting confusing. I made the change to clear that up. Didn't do much for the NPE though. – Jaime Dec 16 '11 at 18:02
  • Sorry, did you find any solution? I have same problem with Lenovo A1_07 – Michael Nov 12 '12 at 14:57

1 Answers1

1

I had the same problem with Lenovo A1_07 and the same error log. But after trial and error, I solved it. I changed VideoView#stopPlayback() to VideoView#pause() and then the problem have been solved completely.

Undo
  • 25,519
  • 37
  • 106
  • 129
Yohpapa
  • 11
  • 2