0

Androidゲーム開発初心者です。エミュレーターと私のAndroidデバイスの1つですべて正常に動作しますが、nexus 4でクラッシュします...

を使用してユーザーのタッチを取得しようとしています

@Override
public boolean dispatchTouchEvent(MotionEvent event) {

    if(!jump){
    first=true;
    makeajump();
    }

    return super.dispatchTouchEvent(event);
}

これは、nexus でのデバッグ モード テストでエラーが発生する場所です。

jcanvas.drawBitmap(mytree, xtree1,height-t1.getHeight(), null);//inside makeajump() line 404

ユーザーが画面をタップするまで、すべて機能します...

jcanvas = canvas;//set in onDraw(),jcanvas is global

エラーが発生したときのログキャットは次のとおりです。

06-18 18:40:55.752: E/InputEventReceiver(8523): Exception dispatching input event.
06-18 18:40:55.752: E/MessageQueue-JNI(8523): Exception in MessageQueue callback: handleReceiveCallback
06-18 18:40:55.762: E/MessageQueue-JNI(8523): java.lang.NullPointerException
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at android.view.GLES20RecordingCanvas.drawBitmap(GLES20RecordingCanvas.java:105)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at lion.run.vjapps.game.animal.GameView.makeajump(GameView.java:404)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at lion.run.vjapps.game.animal.GameView.dispatchTouchEvent(GameView.java:455)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1875)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1875)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1875)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at android.app.Activity.dispatchTouchEvent(Activity.java:2410)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1901)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at android.view.View.dispatchPointerEvent(View.java:7426)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at android.os.MessageQueue.nativePollOnce(Native Method)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at android.os.MessageQueue.next(MessageQueue.java:125)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at android.os.Looper.loop(Looper.java:124)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at android.app.ActivityThread.main(ActivityThread.java:5041)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at java.lang.reflect.Method.invokeNative(Native Method)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at java.lang.reflect.Method.invoke(Method.java:511)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-18 18:40:55.762: E/MessageQueue-JNI(8523):   at dalvik.system.NativeStart.main(Native Method)
06-18 18:40:55.762: D/AndroidRuntime(8523): Shutting down VM
06-18 18:40:55.762: W/dalvikvm(8523): threadid=1: thread exiting with uncaught exception (group=0x41a8d930)
06-18 18:40:55.762: E/AndroidRuntime(8523): FATAL EXCEPTION: main
06-18 18:40:55.762: E/AndroidRuntime(8523): java.lang.NullPointerException
06-18 18:40:55.762: E/AndroidRuntime(8523):     at android.view.GLES20RecordingCanvas.drawBitmap(GLES20RecordingCanvas.java:105)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at lion.run.vjapps.game.animal.GameView.makeajump(GameView.java:404)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at lion.run.vjapps.game.animal.GameView.dispatchTouchEvent(GameView.java:455)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1875)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1875)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1875)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at android.app.Activity.dispatchTouchEvent(Activity.java:2410)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1901)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at android.view.View.dispatchPointerEvent(View.java:7426)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at android.os.MessageQueue.nativePollOnce(Native Method)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at android.os.MessageQueue.next(MessageQueue.java:125)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at android.os.Looper.loop(Looper.java:124)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at android.app.ActivityThread.main(ActivityThread.java:5041)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at java.lang.reflect.Method.invokeNative(Native Method)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at java.lang.reflect.Method.invoke(Method.java:511)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-18 18:40:55.762: E/AndroidRuntime(8523):     at dalvik.system.NativeStart.main(Native Method)

どんな助けでも大歓迎です...どうもありがとう..

4

1 に答える 1

1

描画コードを onDraw() 内に移動する必要があります

       canvas.drawBitmap(mytree, xtree1,height-t1.getHeight(), null);

onDraw() の外で計算を行いinvalidate()、描画を更新するために呼び出すことができます

public void invalidate ()

ビュー全体を無効にします。ビューが表示されている場合、将来のある時点で onDraw(android.graphics.Canvas) が呼び出されます。これは、UI スレッドから呼び出す必要があります。非 UI スレッドから呼び出すには、postInvalidate() を呼び出します。

于 2013-06-18T13:57:04.277 に答える