您好,我目前在 android 市场上的一些应用程序出现错误:
这是堆栈跟踪:
java.lang.NullPointerException
at ****.****.MainActivity.onListItemClick(MainActivity.java:110)
at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
at android.widget.AdapterView.performItemClick(AdapterView.java:284)
at android.widget.ListView.performItemClick(ListView.java:3513)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:870)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
at dalvik.system.NativeStart.main(Native Method)
出错的代码部分:
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
mMediaPlayer.stop();
Sound s = (Sound) l.getItemAtPosition(position);
mMediaPlayer = MediaPlayer.create(this, s.getSoundResourceId());
mMediaPlayer.start();
}
大多数时候它都在工作(播放声音),但有时它会给出一个空指针异常,我不知道为什么可能是 MediaPlayer 或 super.onListItemClick() ?
提前致谢