应用程序的工作方式是我有一个视频列表。视频视图将播放视频,用户可以向左或向右滑动以从视频移动到视频。
这个应用程序在我测试过的所有其他设备上都可以正常工作。(三星Galaxy Tab 7、三星Galaxy播放器、宏碁Iconia A500、Nook Color、LG擎天柱、Kindle Fire)
然后我测试了Nook平板电脑。我得到了一个nullpointerexception。当我向一个方向(vid1>vid2)滑动,然后向另一个方向(vid2>vid1)向后滑动时,就会发生这种情况。
下面是崩溃的代码部分:

  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);
   }

这是我的日志:
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)

我不确定是什么导致了空指针,但我已经试过同时使用这两个
setContentView();
VideoView video = (VideoView) findViewById(R.id.chapterVideoView);

但他们没有成功。在这一点上,我很困惑,希望得到一些帮助。
当做,
詹姆

最佳答案

我对联想a1_07也有同样的问题,也有同样的错误日志。但经过反复试验,我终于解决了。我把VideoView#stopPlayback()改成VideoView#pause(),问题就完全解决了。

关于android - NookTablet Android-VideoView NullPointerException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8528372/

10-12 23:54