成功执行拖放操作后创建新视图

时间:2017-01-10 15:31:10

标签: android drag-and-drop imageview

我有一个在XML中设置为不可见的图像。我想要的是在成功下降后显示此图像。它给了我一个奇怪的错误,我将在下面发布

我的代码

//snippet of my dragdrop code. it is in another helperclass

case MotionEvent.ACTION_UP:
        if (mDragging) {
            drop(screenX, screenY);
        }
        endDrag();

        System.out.println("TARGET DROPPED");
        DragActivityV2 DDA = new DragActivityV2();
        DDA.showPlayAgainBtn();

        break;

这将是我的活动类

 public void showPlayAgainBtn(){

        context = this;
        ImageView imgView = new ImageView(this);
        imgView.findViewById(R.id.playAgain);
        imgView.setVisibility(View.VISIBLE);
    }

这是我的错误。

E/InputEventReceiver: Exception dispatching input event.
E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
E/MessageQueue-JNI: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
                        at android.content.ContextWrapper.getResources(ContextWrapper.java:86)
                        at android.view.ContextThemeWrapper.getResourcesInternal(ContextThemeWrapper.java:127)
                        at android.view.ContextThemeWrapper.getResources(ContextThemeWrapper.java:121)
                        at android.view.View.<init>(View.java:4012)
                        at android.widget.ImageView.<init>(ImageView.java:141)
                        at info.androidhive.tabsswipe.dragview.DragActivityV2.showPlayAgainBtn(DragActivityV2.java:515)
                        at info.androidhive.tabsswipe.dragview.DragController.onTouchEvent(DragController.java:438)
                        at info.androidhive.tabsswipe.dragview.DragLayer.onTouchEvent(DragLayer.java:69)
                        at android.view.View.dispatchTouchEvent(View.java:10023)
                        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2626)
                        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2307)
                        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
                        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2321)
                        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
                        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2321)
                        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
                        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2321)
                        at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:413)
                        at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1808)
                        at android.app.Activity.dispatchTouchEvent(Activity.java:3061)
                        at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:375)
                        at android.view.View.dispatchPointerEvent(View.java:10243)
                        at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4438)
                        at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4306)
                        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3853)
                        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3906)
                        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3872)
                        at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3999)
                        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3880)
                        at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4056)
                        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3853)
                        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3906)
                        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3872)
                        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3880)
                        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3853)
                        at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6246)
                        at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6220)
                        at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6181)
                        at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6349)
                        at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
                        at android.os.MessageQueue.nativePollOnce(Native Method)
                        at android.os.MessageQueue.next(MessageQueue.java:323)
                        at android.os.Looper.loop(Looper.java:136)
                        at android.app.ActivityThread.main(ActivityThread.java:6119)
                        at java.lang.reflect.Method.invoke(Native Method)
                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: info.androidhive.tabsswipe, PID: 11140
                  java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
                      at android.content.ContextWrapper.getResources(ContextWrapper.java:86)
                      at android.view.ContextThemeWrapper.getResourcesInternal(ContextThemeWrapper.java:127)
                      at android.view.ContextThemeWrapper.getResources(ContextThemeWrapper.java:121)
                      at android.view.View.<init>(View.java:4012)
                      at android.widget.ImageView.<init>(ImageView.java:141)
                      at info.androidhive.tabsswipe.dragview.DragActivityV2.showPlayAgainBtn(DragActivityV2.java:515)
                      at info.androidhive.tabsswipe.dragview.DragController.onTouchEvent(DragController.java:438)
                      at info.androidhive.tabsswipe.dragview.DragLayer.onTouchEvent(DragLayer.java:69)
                      at android.view.View.dispatchTouchEvent(View.java:10023)
                      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2626)
                      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2307)
                      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
                      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2321)
                      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
                      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2321)
                      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2632)
                      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2321)
                      at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:413)
                      at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1808)
                      at android.app.Activity.dispatchTouchEvent(Activity.java:3061)
                      at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:375)
                      at android.view.View.dispatchPointerEvent(View.java:10243)
                      at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4438)
                      at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4306)
                      at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3853)
                      at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3906)
                      at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3872)
                      at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3999)
                      at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3880)
                      at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4056)
                      at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3853)
                      at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3906)
                      at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3872)
                      at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3880)
                      at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3853)
                      at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6246)
                      at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6220)
                      at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6181)
                      at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6349)
                      at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
                      at android.os.MessageQueue.nativePollOnce(Native Method)
                      at android.os.MessageQueue.next(MessageQueue.java:323)
                      at android.os.Looper.loop(Looper.java:136)
                      at android.app.ActivityThread.main(ActivityThread.java:6119)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Application terminated.

0 个答案:

没有答案