NookTablet Android - VideoView NullPointerException
该应用程序的工作方式是我有一个视频列表。视频视图将播放视频,用户可以向左或向右滑动以在视频之间移动。
该应用程序在我测试过的所有其他设备上都没有错误。 (三星 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 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()
toVideoView#pause()
and then the problem have been solved completely.