0

I have develop an app which has task for playing video SDcard. But it shows Null pointer Exception... Code below...

public class VideoPlayerActivity extends Activity {
VideoView video_player_view;
DisplayMetrics dm;
SurfaceView sur_View;
MediaController media_Controller;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    getInit();
    }

public void getInit() {
    try {
    video_player_view = (VideoView) findViewById(R.id.video_player_view);
    media_Controller = new MediaController(getApplicationContext());
    dm = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(dm);
    int height = dm.heightPixels;
    int width = dm.widthPixels;
    video_player_view.setMinimumWidth(width);
    video_player_view.setMinimumHeight(height);
    video_player_view.setMediaController(media_Controller);
    video_player_view.setVideoPath("/storage/sdcard0/baby.3gp");
    video_player_view.start();
    } catch(Exception exp) {
        Toast.makeText(getApplicationContext(), exp.getMessage(), 2).show();
    }
}}

I have using Micromax A210 for dispaying output. My Logcat is below

12-02 19:04:52.785: D/OpenGLRenderer(3950): Enabling debug mode 0
12-02 19:04:52.787: I/SurfaceView(3950): Changes: creating=true format=true size=true visible=true left=true top=true mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceSizeChanged=true mVisible=false mRequestedVisible=true
12-02 19:04:52.788: I/SurfaceView(3950): Cur surface: Surface(name=null, identity=-1)
12-02 19:04:52.791: V/SurfaceView(3950): android.widget.VideoView{41688140 VFE..... .F....ID 0,0-1280,590 #7f06003d app:id/video_player_view} got resized: w=1280 h=590, cur w=-1 h=-1
12-02 19:04:52.793: I/SurfaceView(3950): New surface: Surface(name=null, identity=33), vis=true, frame=Rect(0, 130 - 1280, 720)
12-02 19:04:52.793: I/SurfaceView(3950): visibleChanged -- surfaceCreated
12-02 19:04:52.798: D/MediaPlayer(3950): mPlayerID = 2
12-02 19:04:52.799: D/MediaPlayer(3950): Don't notify duration to test.example.videoviewtesting!
12-02 19:04:52.799: I/SurfaceView(3950): finishedDrawing
12-02 19:04:52.799: E/MediaPlayer(3950): error (1, -2147483648)
12-02 19:04:52.802: D/AndroidRuntime(3950): Shutting down VM
12-02 19:04:52.802: W/dalvikvm(3950): threadid=1: thread exiting with uncaught exception (group=0x4139c9a8)
12-02 19:04:52.804: E/AndroidRuntime(3950): FATAL EXCEPTION: main
12-02 19:04:52.804: E/AndroidRuntime(3950): java.lang.NullPointerException
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.widget.VideoView.openVideo(VideoView.java:396)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.widget.VideoView$6.surfaceCreated(VideoView.java:730)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.view.SurfaceView.updateWindow(SurfaceView.java:606)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.view.SurfaceView.access$000(SurfaceView.java:88) 
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:183)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:692)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2123)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1139)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4879)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.view.Choreographer.doCallbacks(Choreographer.java:579)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.view.Choreographer.doFrame(Choreographer.java:548)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.os.Handler.handleCallback(Handler.java:725)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.os.Looper.loop(Looper.java:153)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at android.app.ActivityThread.main(ActivityThread.java:5297)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at java.lang.reflect.Method.invokeNative(Native Method)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at java.lang.reflect.Method.invoke(Method.java:511)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
12-02 19:04:52.804: E/AndroidRuntime(3950):     at dalvik.system.NativeStart.main(Native Method)
12-02 19:04:52.814: D/dalvikvm(3950): threadid=11: interp stack at 0x5e220000

I have updated my main.xml file. Dont know where can i resizing the view...

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="video.sample.videosample.MainActivity"
android:orientation="vertical"
tools:ignore="MergeRootFrame" >

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <VideoView
        android:id="@+id/myvideoview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
Android
  • 1
  • 3
  • i have played the video in raw folder, But it not plays from SDcard. I tried http://stackoverflow.com/questions/10869830/how-to-play-videos-from-sd-card, http://stackoverflow.com/questions/11406603/how-to-play-a-video-file-from-sd-card, http://android-coding.blogspot.in/2011/03/using-videoview-to-play-mp4-from-sdcard.html, https://www.youtube.com/watch?v=TsCQUjGEusQ... I dont know what mistake i have done, and where it will produces the null pointer.. Please help me... – Android Dec 02 '15 at 14:06
  • Oh god... Atleast tell me where is the exception. This task totally damaged me... – Android Dec 02 '15 at 14:44
  • I think your attempts at resizing the view to full screen is causing a problem. Since you didn't provide your main layout xml, see: http://stackoverflow.com/questions/3776254/android-video-view-in-fullscreen and don't forget about correctly accessing the SD card rather than the hardcode pathname you have there. – Morrison Chang Dec 02 '15 at 16:34
  • @Morrison i have updated my xml file sir. please tell me what is the error in my file... in my case my file path is "/storage/sdcard0/baby.3gp". – Android Dec 03 '15 at 10:30

0 Answers0