今天我收到了NullPointerException
報告。我無法在自己的手機上重現此NullPointerException。來自Play商店的NullPointerException報告
我真的找不到是什麼導致NullPointerException。
下面是報告:
java.lang.NullPointerException
at com.dsf.sdf.ManActivity$25.onTouch(ManActivity.java:445)
at android.view.View.dispatchTouchEvent(View.java:3762)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
at com.android.internal.policy.impl.PhoneWindow$DecorView.
(PhoneWindow.java:1674)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1109)
at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
at com.android.internal.policy.impl.PhoneWindow$DecorView.
dispatchTouchEvent(PhoneWindow.java:1658)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1785)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.
run(ZygoteInit.java:876)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634)
at dalvik.system.NativeStart.main(Native Method)
下面是從線936代碼:
sdff.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
sdff.setBackgroundDrawable(getResources().
getDrawable(R.drawable.pressed));
}
else if (event.getAction() == MotionEvent.ACTION_UP) {
if (play != null) {
play.reset();
play.release();
}
play = MediaPlayer.create(ManActivity.this,
R.raw.sdff);
play.start();
sdff.setBackgroundDrawable(getResources().
getDrawable(R.drawable.button));
}
else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
sdff.setBackgroundDrawable(getResources().
getDrawable(R.drawable.button));
}
return false;
}
});
這是一個簡單的按鈕按下至極時播放聲音。
那麼是什麼導致了異常?
編輯:
Code at line 445:
play = MediaPlayer.create(ManActivity.this,
R.raw.bf);
play.start();
auth.setBackgroundDrawable(getResources().getDrawable(
R.drawable.button));
這是ManActivity.java中第445行的語句? – Rajesh
Hm,如果MediaPlayer.create'失敗,則可以返回null。因爲你的聲音被打包爲一個資源 – Jens
那麼你如何解決Mediaplayer.create爲null?只是嘗試捕捉?你是對的聲音被打包爲資源,但我有另一個報告(第二個)。它可以是電話可靠嗎?例如:它可以在新的三星設備上正常工作,但由於nullpointerexception而在HTC設備上崩潰?這可能嗎? – MeesterPatat