0

I am trying to play a .wma audio file in my android application. But the app gives NULL POINTER EXCEPTION while playing wma file but works completely fine with mp3 files Code :

public class Sounds extends Activity{
    private MediaPlayer mp;
    private Button bbb;
    boolean flag = true;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sounds);
        setVolumeControlStream(AudioManager.STREAM_MUSIC);
        bbb = (Button)findViewById(R.id.buttonSong);
        bbb.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub  
                if(mp == null)
            mp=MediaPlayer.create(getApplicationContext(),R.raw.testing);
            if(mp.isPlaying())
            {
                mp.pause();
                bbb.setText("Pause");
            }
            else
            {
                mp.start();
                bbb.setText("Start");
            }
            }
            });
    }
    }

Log Cat :

02-10 21:13:39.912: E/AndroidRuntime(19350): FATAL EXCEPTION: main
02-10 21:13:39.912: E/AndroidRuntime(19350): java.lang.NullPointerException
02-10 21:13:39.912: E/AndroidRuntime(19350):    at com.example.audiotest.Sounds$1.onClick(Sounds.java:29)
02-10 21:13:39.912: E/AndroidRuntime(19350):    at android.view.View.performClick(View.java:4147)
02-10 21:13:39.912: E/AndroidRuntime(19350):    at android.view.View$PerformClick.run(View.java:17161)
02-10 21:13:39.912: E/AndroidRuntime(19350):    at android.os.Handler.handleCallback(Handler.java:615)
02-10 21:13:39.912: E/AndroidRuntime(19350):    at android.os.Handler.dispatchMessage(Handler.java:92)
02-10 21:13:39.912: E/AndroidRuntime(19350):    at android.os.Looper.loop(Looper.java:213)
02-10 21:13:39.912: E/AndroidRuntime(19350):    at android.app.ActivityThread.main(ActivityThread.java:4787)
02-10 21:13:39.912: E/AndroidRuntime(19350):    at java.lang.reflect.Method.invokeNative(Native Method)
02-10 21:13:39.912: E/AndroidRuntime(19350):    at java.lang.reflect.Method.invoke(Method.java:511)
02-10 21:13:39.912: E/AndroidRuntime(19350):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
02-10 21:13:39.912: E/AndroidRuntime(19350):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
02-10 21:13:39.912: E/AndroidRuntime(19350):    at dalvik.system.NativeStart.main(Native Method)
  • 2
    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) – Jens Feb 10 '16 at 14:27
  • @Jens My question is not that what is NPE. The problem is while playing wma audio file, android app throws NPE but works fine with mp3 files. – Rachit Srivastava Feb 10 '16 at 14:32
  • I advice you deleting your question othervise it will continue downwoting :( . – katmanco Feb 10 '16 at 14:33
  • 1
    Error question without code or stacktrace ? No problem, [I'll just guess](https://media.giphy.com/media/BZUXTEvJSPsUo/giphy.gif)... – 2Dee Feb 10 '16 at 14:37
  • 1
    @RachitSrivastava please tag me if u get any solution :)...did +1 good question ...but on S/O users like to downvote more than to upvote instead of suggesting possible answers. – Animesh Mangla Feb 10 '16 at 15:00
  • @RachitSrivastava add your `Exception` stack trace, we ain't clairvoyants. Without seeing the complete stack trace one can guess forever – Droidman Feb 10 '16 at 15:00
  • There is a very accessible tutorial on the official site explaining how to use MediaPlayer. I'm here wondering why you thought it shouldn't concern you and went with your own code (which obviously doesn't work) instead... Maybe RTFM ? – 2Dee Feb 11 '16 at 16:53

0 Answers0