-1

I am using standout library, I added a videoView in it, Everything is running correctly, Except if i click on video then mediaController Is not Showing and i am getting null pointer exception. Here is my code:-

final LayoutInflater inflater = (LayoutInflater)    
 getSystemService(LAYOUT_INFLATER_SERVICE);
    final View view = inflater.inflate(R.layout.simple, frame, true);
    localVideoView = (VideoView) view.findViewById(R.id.videoView1);
    MediaController mediaController = new MediaController(StandOutExampleActivity.getActivity());
    mediaController.setAnchorView(localVideoView);
    localVideoView.setMediaController(mediaController);
    localVideoView.setVideoPath("android.resource://" + getPackageName() + "/" 
            + R.raw.ba);
    localVideoView.start();

Log File:-

    67: E/AndroidRuntime(1997): FATAL EXCEPTION: main
    01-14 19:48:56.767: E/AndroidRuntime(1997): java.lang.NullPointerException
    01-14 19:48:56.767: E/AndroidRuntime(1997):     at android.view.View.onAttachedToWindow(View.java:11709)
    01-14 19:48:56.767: E/AndroidRuntime(1997):     at android.view.View.dispatchAttachedToWindow(View.java:12125)
    01-14 19:48:56.767: E/AndroidRuntime(1997):     at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2450)
    01-14 19:48:56.767: E/AndroidRuntime(1997):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1207)
    01-14 19:48:56.767: E/AndroidRuntime(1997):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
    01-14 19:48:56.767: E/AndroidRuntime(1997):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
    01-14 19:48:56.767: E/AndroidRuntime(1997):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
    01-14 19:48:56.767: E/AndroidRuntime(1997):     at android.view.Choreographer.doCallbacks(Choreographer.java:562)
    01-14 19:48:56.767: E/AndroidRuntime(1997):     at android.view.Choreographer.doFrame(Choreographer.java:532)
    01-14 19:48:56.767: E/AndroidRuntime(1997):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
    01-14 19:48:56.767: E/AndroidRuntime(1997):     at android.os.Handler.handleCallback(Handler.java:730)
    01-14 19:48:56.767: E/AndroidRuntime(1997):     at android.os.Handler.dispatchMessage(Handler.java:92)
    01-14 19:48:56.767: E/AndroidRuntime(1997):     at android.os.Looper.loop(Looper.java:137)
    01-14 19:48:56.767: E/AndroidRuntime(1997):     at android.app.ActivityThread.main(ActivityThread.java:5103)
    01-14 19:48:56.767: E/AndroidRuntime(1997):     at java.lang.reflect.Method.invokeNative(Native Method)
    01-14 19:48:56.767: E/AndroidRuntime(1997):     at java.lang.reflect.Method.invoke(Method.java:525)
    01-14 19:48:56.767: E/AndroidRuntime(1997):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    01-14 19:48:56.767: E/AndroidRuntime(1997):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    01-14 19:48:56.767: E/AndroidRuntime(1997):     at dalvik.system.NativeStart.main(Native Method)
  • can you post your log – Moubeen Farooq Khan Jan 15 '15 at 18:41
  • possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – Najera Jan 15 '15 at 18:42
  • I know what is null pointer exception but i added everything correct on videoview so why i am getting this exception? – ankur agarwal Jan 15 '15 at 18:44
  • Log File Added @MoubeenFarooqWarar – ankur agarwal Jan 15 '15 at 18:51
  • I am not expert, but are you sure what localVideoView.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.ba); is correct path? This string looks suspicious – Kirill Shalnov Jan 15 '15 at 19:18
  • Ya That is one correct, My video is playing and i am changing video, But If i click on video then my app crashes. I dont know why – ankur agarwal Jan 15 '15 at 19:20
  • I traced code and i found that some problem in MediaController mediaController = new MediaController(StandOutExampleActivity.a); this line. – ankur agarwal Jan 15 '15 at 19:23
  • Have you added the `WRITE_EXTERNAL_STORAGE` permission to your `AndroidManifest`? If not, trying to set the video path and save the video could cause a `NullPointerException`. – Willis Jan 15 '15 at 19:29
  • Yes, I added line to my manifest file – ankur agarwal Jan 15 '15 at 19:32
  • I all-ready told you that i am using standout library so if you are not familiar with that then i am telling you that i am using this code like in a service class, Not in activity. – ankur agarwal Jan 15 '15 at 19:34

1 Answers1

0

If your application loads and plays the video fine but crashes when you click on the screen, the most likely reason is that your VideoView does not know how to handle touch events. Try adding the following to your code:

localVideoView.setOnTouchListener(new View.OnTouchListener()
{
    @Override
    public boolean onTouch(View v, MotionEvent event)
    {
        // Execute action on touch event
        return true;
    }
});

The code snippet above sets up a listener for touch events so that they do not go unhandled.

Willis
  • 5,308
  • 3
  • 32
  • 61