我有一个crated和应用程序,它从SD卡上的文件播放视频。应用程序在移动设备启动时启动。当设备重新启动时,应用程序将等待直到安装SD卡,然后它会获取SD卡上的文件路径并尝试使用MediaPlayer api播放该文件。但应用程序崩溃与下面的日志。 如果用户在设备运行且未启动时手动启动应用程序,该应用程序可以正常运行。
09-22 18:53:39.700: W/System.err(1302): java.lang.NullPointerException
09-22 18:53:39.700: W/System.err(1302): at java.io.File.fixSlashes(File.java:185)
09-22 18:53:39.700: W/System.err(1302): at java.io.File.<init>(File.java:134)
09-22 18:53:39.700: W/System.err(1302): at com.sherbet.taxi.FullVideoActivity.setUpVideoFrom(FullVideoActivity.java:225)
09-22 18:53:39.700: W/System.err(1302): at com.sherbet.taxi.FullVideoActivity.onCreate(FullVideoActivity.java:112)
09-22 18:53:39.700: W/System.err(1302): at android.app.Activity.performCreate(Activity.java:5008)
09-22 18:53:39.700: W/System.err(1302): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
09-22 18:53:39.700: W/System.err(1302): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2035)
09-22 18:53:39.700: W/System.err(1302): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
09-22 18:53:39.700: W/System.err(1302): at android.app.ActivityThread.access$600(ActivityThread.java:138)
09-22 18:53:39.700: W/System.err(1302): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
09-22 18:53:39.700: W/System.err(1302): at android.os.Handler.dispatchMessage(Handler.java:99)
09-22 18:53:39.700: W/System.err(1302): at android.os.Looper.loop(Looper.java:213)
09-22 18:53:39.700: W/System.err(1302): at android.app.ActivityThread.main(ActivityThread.java:4787)
09-22 18:53:39.700: W/System.err(1302): at java.lang.reflect.Method.invokeNative(Native Method)
09-22 18:53:39.700: W/System.err(1302): at java.lang.reflect.Method.invoke(Method.java:511)
09-22 18:53:39.700: W/System.err(1302): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
09-22 18:53:39.700: W/System.err(1302): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
09-22 18:53:39.700: W/System.err(1302): at dalvik.system.NativeStart.main(Native Method)
09-22 18:53:39.730: E/MediaPlayer(1302): error (1, -2147483648)
09-22 18:53:39.830: E/MediaPlayer(1302): prepareAsync called in state 1
09-22 18:53:39.830: W/System.err(1302): java.lang.IllegalStateException
09-22 18:53:39.830: W/System.err(1302): at android.media.MediaPlayer.prepare(Native Method)
09-22 18:53:39.830: W/System.err(1302): at com.sherbet.taxi.FullVideoActivity.play(FullVideoActivity.java:187)
09-22 18:53:39.830: W/System.err(1302): at com.sherbet.taxi.FullVideoActivity.surfaceChanged(FullVideoActivity.java:354)
09-22 18:53:39.830: W/System.err(1302): at android.view.SurfaceView.updateWindow(SurfaceView.java:558)
09-22 18:53:39.840: W/System.err(1302): at android.view.SurfaceView.access$000(SurfaceView.java:85)
09-22 18:53:39.840: W/System.err(1302): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:173)
09-22 18:53:39.840: W/System.err(1302): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:671)
09-22 18:53:39.840: W/System.err(1302): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1828)
09-22 18:53:39.840: W/System.err(1302): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
09-22 18:53:39.840: W/System.err(1302): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4223)
09-22 18:53:39.840: W/System.err(1302): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
09-22 18:53:39.840: W/System.err(1302): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
09-22 18:53:39.840: W/System.err(1302): at android.view.Choreographer.doFrame(Choreographer.java:525)
09-22 18:53:39.840: W/System.err(1302): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
09-22 18:53:39.840: W/System.err(1302): at android.os.Handler.handleCallback(Handler.java:615)
09-22 18:53:39.850: W/System.err(1302): at android.os.Handler.dispatchMessage(Handler.java:92)
09-22 18:53:39.850: W/System.err(1302): at android.os.Looper.loop(Looper.java:213)
09-22 18:53:39.850: W/System.err(1302): at android.app.ActivityThread.main(ActivityThread.java:4787)
09-22 18:53:39.850: W/System.err(1302): at java.lang.reflect.Method.invokeNative(Native Method)
09-22 18:53:39.850: W/System.err(1302): at java.lang.reflect.Method.invoke(Method.java:511)
09-22 18:53:39.850: W/System.err(1302): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
09-22 18:53:39.850: W/System.err(1302): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
09-22 18:53:39.850: W/System.err(1302): at dalvik.system.NativeStart.main(Native Method)
09-22 18:53:39.860: E/MediaPlayer(1302): Error (1,-2147483648)
代码是:
File file = new File(videoUrl);
file.setReadable(true, false);
Utils.ShowLogMsg("filepath: " + file.getAbsolutePath()
+ " exists: " + file.exists());
FileInputStream inputStream = new FileInputStream(file);
FileDescriptor fd = inputStream.getFD();
Utils.ShowLogMsg("file length: " + file.length());
**
mPlayer.setDataSource(fd, 0, file.length());
inputStream.close();
**
应用程序出现在代码中突出显示的行。任何人都可以帮我解决这个问题。
由于 Ishan jain