3
我有一個媒體控制器的問題,這部分代碼在不同的設備上完美地工作,如宏碁液體(薑餅),愛可視43(Froyo)和愛可視32(Froyo)...Crash on MediaController.show()
VideoView videoView = (VideoView) findViewById(R.id.videoView1);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
File filevideo = new File(Environment.getExternalStorageDirectory() + "/edizionitsm/firenze/map_" + map_n + "/",filename + "_" + language + ".mp4");
Uri video = Uri.fromFile(filevideo);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
......但是在視角臨表2(薑餅)它在活動開始時崩潰。
11-09 14:12:59.640: E/AndroidRuntime(31433): FATAL EXCEPTION: main
11-09 14:12:59.640: E/AndroidRuntime(31433): java.lang.RuntimeException: Unable to start activity ComponentInfo{edizionitsm.archeoplayer/edizionitsm.archeoplayer.Player}: java.lang.NullPointerException
11-09 14:12:59.640: E/AndroidRuntime(31433): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
11-09 14:12:59.640: E/AndroidRuntime(31433): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
11-09 14:12:59.640: E/AndroidRuntime(31433): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-09 14:12:59.640: E/AndroidRuntime(31433): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
11-09 14:12:59.640: E/AndroidRuntime(31433): at android.os.Handler.dispatchMessage(Handler.java:99)
11-09 14:12:59.640: E/AndroidRuntime(31433): at android.os.Looper.loop(Looper.java:123)
11-09 14:12:59.640: E/AndroidRuntime(31433): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-09 14:12:59.640: E/AndroidRuntime(31433): at java.lang.reflect.Method.invokeNative(Native Method)
11-09 14:12:59.640: E/AndroidRuntime(31433): at java.lang.reflect.Method.invoke(Method.java:507)
11-09 14:12:59.640: E/AndroidRuntime(31433): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-09 14:12:59.640: E/AndroidRuntime(31433): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-09 14:12:59.640: E/AndroidRuntime(31433): at dalvik.system.NativeStart.main(Native Method)
11-09 14:12:59.640: E/AndroidRuntime(31433): Caused by: java.lang.NullPointerException
11-09 14:12:59.640: E/AndroidRuntime(31433): at android.widget.MediaController.disableUnsupportedButtons(MediaController.java:640)
11-09 14:12:59.640: E/AndroidRuntime(31433): at android.widget.MediaController.show(MediaController.java:674)
11-09 14:12:59.640: E/AndroidRuntime(31433): at android.widget.MediaController.show(MediaController.java:631)
11-09 14:12:59.640: E/AndroidRuntime(31433): at android.widget.VideoView.start(VideoView.java:962)
11-09 14:12:59.640: E/AndroidRuntime(31433): at edizionitsm.archeoplayer.Player.onCreate(Player.java:48)
11-09 14:12:59.640: E/AndroidRuntime(31433): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-09 14:12:59.640: E/AndroidRuntime(31433): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
11-09 14:12:59.640: E/AndroidRuntime(31433): ... 11 more
問題出在mediacontroller類的show()函數中。我該如何解決它? 謝謝。
什麼是代碼行和所有相關的代碼在這裏:edizionitsm.archeoplayer.Player.onCreate(Player.java:48)? –
問題出在這裏:'由於:java.lang.NullPointerException 11-09 14:12:59.640:E/AndroidRuntime(31433):at android.widget.MediaController.disableUnsupportedButtons(MediaController.java:640)'。我得到了同樣的異常(在Android 4.0.3上),但只在顯式調用mediaController.show()時。如果沒有,它可以工作,但不會自動顯示媒體控制器 - 只有當我觸摸視頻時,但至少沒有崩潰。 – Ridcully