Mohammad Hammad
Mohammad Hammad

Reputation: 491

error on some devices

I got this error report from some devices while on others application is working so fine !!!

java.lang.NullPointerException
at com.hamoosh.birdseffects.De7katGrid$1.onItemClick(De7katGrid.java:44)
at android.widget.AdapterView.performItemClick(AdapterView.java:292)
at android.widget.AbsListView.performItemClick(AbsListView.java:1359)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:2988)
at android.widget.AbsListView$1.run(AbsListView.java:3783)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)

where no errors on source code ??

error line is 44 shown in this part of code

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

    GridView gridView = (GridView) findViewById(R.id.grid_view);

    // Instance of ImageAdapter Class
    gridView.setAdapter(new ImageAdapter(this));

    gridView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View v,
                int position, long id) {
            stopPlaying();
            mp = MediaPlayer.create(De7katGrid.this, mSongsIds[position]);
            mp.start();// << here is line 44 !!!
        }
    });
}

Upvotes: 0

Views: 78

Answers (1)

DeeV
DeeV

Reputation: 36035

MediaPlayer.create returns null when the sound file at the resource ID is either not supported by the device, doesn't exist, or is corrupt.

In this case, you're using .wav files which may not be supported on certain devices. If you're sampling rate for the file. They're only guaranteed to be supported on devices 4.1+. Here is the list of supported formats:

http://developer.android.com/guide/appendix/media-formats.html

Upvotes: 2

Related Questions