我从某些设备收到此错误报告,而其他应用程序工作得非常好!!!
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)
源代码没有错误?
这段代码
中显示错误行44@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 !!!
}
});
}
答案 0 :(得分:2)
当资源ID的声音文件不被设备支持,不存在或已损坏时,MediaPlayer.create将返回null。
在这种情况下,您使用的是某些设备可能不支持的.wav文件。如果您是该文件的采样率。它们仅保证在4.1+设备上得到支持。以下是支持的格式列表:
http://developer.android.com/guide/appendix/media-formats.html