有人知道为什么这段代码不能阻止我的播放器播放吗?
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
if(pos == 1) {
if (aacPlayer != null) {
aacPlayer.stop();
aacPlayer = null;
}
}
}
我运行应用程序,当我选择应该停止 aacplayer 的微调器的某个值时,我得到这个:
05-29 12:14:59.279: E/AACPlayer(1608): java.lang.NullPointerException
05-29 12:14:59.279: E/AACPlayer(1608): at com.spoledge.aacplay.AACPlayerActivity.onItemSelected(AACPlayerActivity.java:380)
05-29 12:14:59.279: E/AACPlayer(1608): at android.widget.AdapterView.fireOnSelected(AdapterView.java:871)
05-29 12:14:59.279: E/AACPlayer(1608): at android.widget.AdapterView.access$200(AdapterView.java:42)
05-29 12:14:59.279: E/AACPlayer(1608): at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:837)
05-29 12:14:59.279: E/AACPlayer(1608): at android.os.Handler.handleCallback(Handler.java:587)
05-29 12:14:59.279: E/AACPlayer(1608): at android.os.Handler.dispatchMessage(Handler.java:92)
05-29 12:14:59.279: E/AACPlayer(1608): at android.os.Looper.loop(Looper.java:123)
05-29 12:14:59.279: E/AACPlayer(1608): at android.app.ActivityThread.main(ActivityThread.java:3683)
05-29 12:14:59.279: E/AACPlayer(1608): at java.lang.reflect.Method.invokeNative(Native Method)
05-29 12:14:59.279: E/AACPlayer(1608): at java.lang.reflect.Method.invoke(Method.java:507)
05-29 12:14:59.279: E/AACPlayer(1608): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-29 12:14:59.279: E/AACPlayer(1608): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-29 12:14:59.279: E/AACPlayer(1608): at dalvik.system.NativeStart.main(Native Method)