在videoView:Android v 4.2.1中播放video时出现java.lang.StringIndexOutOfBoundsException

当我在Android版本4.2.1中的videoView上播放video时,我遇到了这个崩溃。 我在Micromax Canvas A210设备上特别发现了这一点。 它没有显示发生错误的任何消息。 这是一个错误或应用程序中的错误吗? 崩溃日志如下:

09-18 11:05:53.245: E/AndroidRuntime(2323): FATAL EXCEPTION: main 09-18 11:05:53.245: E/AndroidRuntime(2323): java.lang.StringIndexOutOfBoundsException: length=11; regionStart=0; regionLength=-1 09-18 11:05:53.245: E/AndroidRuntime(2323): at java.lang.String.startEndAndLength(String.java:583) 09-18 11:05:53.245: E/AndroidRuntime(2323): at java.lang.String.substring(String.java:1464) 09-18 11:05:53.245: E/AndroidRuntime(2323): at android.widget.VideoView.openVideo(VideoView.java:407) 09-18 11:05:53.245: E/AndroidRuntime(2323): at android.widget.VideoView$6.surfaceCreated(VideoView.java:730) 09-18 11:05:53.245: E/AndroidRuntime(2323): at android.view.SurfaceView.updateWindow(SurfaceView.java:606) 09-18 11:05:53.245: E/AndroidRuntime(2323): at android.view.SurfaceView.access$000(SurfaceView.java:88) 09-18 11:05:53.245: E/AndroidRuntime(2323): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:183) 09-18 11:05:53.245: E/AndroidRuntime(2323): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:692) 09-18 11:05:53.245: E/AndroidRuntime(2323): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2123) 09-18 11:05:53.245: E/AndroidRuntime(2323): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1139) 09-18 11:05:53.245: E/AndroidRuntime(2323): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4879) 09-18 11:05:53.245: E/AndroidRuntime(2323): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776) 09-18 11:05:53.245: E/AndroidRuntime(2323): at android.view.Choreographer.doCallbacks(Choreographer.java:579) 09-18 11:05:53.245: E/AndroidRuntime(2323): at android.view.Choreographer.doFrame(Choreographer.java:548) 09-18 11:05:53.245: E/AndroidRuntime(2323): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762) 09-18 11:05:53.245: E/AndroidRuntime(2323): at android.os.Handler.handleCallback(Handler.java:725) 09-18 11:05:53.245: E/AndroidRuntime(2323): at android.os.Handler.dispatchMessage(Handler.java:92) 09-18 11:05:53.245: E/AndroidRuntime(2323): at android.os.Looper.loop(Looper.java:153) 09-18 11:05:53.245: E/AndroidRuntime(2323): at android.app.ActivityThread.main(ActivityThread.java:5297) 09-18 11:05:53.245: E/AndroidRuntime(2323): at java.lang.reflect.Method.invokeNative(Native Method) 09-18 11:05:53.245: E/AndroidRuntime(2323): at java.lang.reflect.Method.invoke(Method.java:511) 09-18 11:05:53.245: E/AndroidRuntime(2323): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) 09-18 11:05:53.245: E/AndroidRuntime(2323): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 09-18 11:05:53.245: E/AndroidRuntime(2323): at dalvik.system.NativeStart.main(Native Method) 

我测试过我的应用程序并且工作正常的其他版本和设备是:

 Android versions: 4.1.2, 4.2.2, 4.3, 2.3.3, 4.0.3, 4.0.4 Devices: Samsung Galaxy s2, Samsung Galaxy Tab 2 (7" and 10"), Samsung Galaxy s plus, Sony Xperia Tipo dual, Samsung Galaxy Grand (Quatro and Mega), Nexus 4 

Solutions Collecting From Web of "在videoView:Android v 4.2.1中播放video时出现java.lang.StringIndexOutOfBoundsException"

您是开发人员并在您的应用程序中使用Video View。 如果是这样,请尝试调试并validation您是否向video视图提供了有效的uri / url。 虽然在android.widget.VideoView类的openVideo()中有空检查,但uri可能是空字符串。

以下是您提到的Android版本的Video View类的来源。

我遇到了同样的问题,发现使用videoview时这是一个micromax特定的bug。 这是在android中使用“TextureView”的另一种方法

BackGroundVideo.java

 public class BackGroundVideo extends AppCompatActivity implements TextureView.SurfaceTextureListener { ProfileTracker profileTracker; private MediaPlayer mMediaPlayer; private TextureView mTextureView; private static final String TAG = sus.class.getName(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash_layout); initView(); } private void initView() { mTextureView = (TextureView) findViewById(R.id.play_video_texture); // SurfaceTexture is available only after the TextureView // is attached to a window and onAttachedToWindow() has been invoked. // We need to use SurfaceTextureListener to be notified when the SurfaceTexture // becomes available. mTextureView.setSurfaceTextureListener(this); } @Override public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) { Surface surface = new Surface(surfaceTexture); mMediaPlayer.prepareAsync(); // Play video when the media source is ready for playback. mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mediaPlayer) { mediaPlayer.start(); } }); } catch (IllegalArgumentException e) { Log.d(TAG, e.getMessage()); } catch (SecurityException e) { Log.d(TAG, e.getMessage()); } catch (IllegalStateException e) { Log.d(TAG, e.getMessage()); } catch (IOException e) { Log.d(TAG, e.getMessage()); } } @Override public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { } @Override public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { return false; } @Override public void onSurfaceTextureUpdated(SurfaceTexture surface) { } 

}

      

splash_layout.xml

希望这对你有用!