NookTablet Android - VideoView NullPointerException

发布于 2024-12-21 14:36:57 字数 4379 浏览 1 评论 0原文

该应用程序的工作方式是我有一个视频列表。视频视图将播放视频,用户可以向左或向右滑动以在视频之间移动。

该应用程序在我测试过的所有其他设备上都没有错误。 (三星 Galaxy Tab 7、三星 Galaxy Player、宏碁 Iconia A500、Nook Color、LG Optimus、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);

但它们没有成功。此时我很困惑,希望得到一些帮助。

问候,

海梅

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天涯离梦残月幽梦 2024-12-28 14:36:57

我在 Lenovo A1_07 上遇到了同样的问题,并且有相同的错误日志。但经过反复尝试,我解决了。我将 VideoView#stopPlayback() 更改为 VideoView#pause() 然后问题就完全解决了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文