向下滑动崩溃应用程序

时间:2018-01-19 01:38:01

标签: java android swipe

所以我正在使用Pwittchen的Swipe库,正在使用的代码是这一部分:

CoreActivity.java

 @Override
        public void onSwipedDown(final MotionEvent event) {

            if(m_Toolbar.getVisibility() == View.VISIBLE ){
                WebShrink.cancel();
            }
            //WebView Animation (Shrink)
           // if(m_WebView.getAnimation().hasStarted() || m_WebView.getAnimation().hasEnded()){
            if(WebEnlarge.hasStarted()){
                WebShrink = AnimationUtils.loadAnimation(CoreActivity.this,R.anim.m_webview_shrink);
                m_WebView.startAnimation(WebShrink);
                m_Preference_Toolbar.setVisibility(View.GONE);
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        m_Toolbar.setVisibility(View.VISIBLE);
                    }
                }, 350);//3 seconds
            }
        }

目前,如果您在创建时向下滑动,我会崩溃。我试图找到解决方法:

 if(m_Toolbar.getVisibility() == View.VISIBLE ){
            WebShrink.cancel();
        }

但这不起作用,我想知道是否有人可以帮助我。理想的情况是,如果工具栏可见或者WebShrink已经到位,那么什么都不做,但我无法找到它周围

logcat的

 01-18 20:57:23.652 29764-29764/com.equiware.mickeyt.fire    E/InputEventReceiver: Exception dispatching input event.
01-18 20:57:23.653 29764-29764/com.equiware.mickeyt.fire D/AndroidRuntime: Shutting down VM
01-18 20:57:23.654 29764-29764/com.equiware.mickeyt.fire E/AndroidRuntime: FATAL EXCEPTION: main
                                                                         Process: com.equiware.mickeyt.fire, PID: 29764
                                                                        java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.animation.Animation.cancel()' on a null object reference
                                                                           at com.equiware.mickeyt.fire.CoreActivity$2.onSwipedDown(CoreActivity.java:161)
                                                                           at com.github.pwittchen.swipe.library.rx2.Swipe.onActionUp(Swipe.java:138)
                                                                             at  com.github.pwittchen.swipe.library.rx2.Swipe.dispatchTouchEvent(Swipe.java:101)
                                                                           at com.equiware.mickeyt.fire.CoreActivity.dispatchTouchEvent(CoreActivity.java:216)
                                                                           at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:68)
                                                                           at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:374)
                                                                           at android.view.View.dispatchPointerEvent(View.java:10177)
                                                                           at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4628)
                                                                           at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4496)
                                                                           at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3947)
                                                                           at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4000)
                                                                           at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3966)
                                                                           at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3974)
                                                                           at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3947)
                                                                           at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4000)
                                                                           at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3966)
                                                                           at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4095)
                                                                           at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3974)
                                                                           at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4152)
                                                                           at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3947)
                                                                           at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4000)
                                                                           at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3966)
                                                                           at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3974)
                                                                           at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3947)
                                                                           at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6437)
                                                                           at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6411)
                                                                           at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6372)
                                                                           at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6571)
                                                                           at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
                                                                           at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
                                                                           at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176)
                                                                           at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:6519)
                                                                           at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:6594)
                                                                           at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
                                                                           at android.view.Choreographer.doCallbacks(Choreographer.java:683)
                                                                           at android.view.Choreographer.doFrame(Choreographer.java:613)
                                                                           at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
                                                                           at android.os.Handler.handleCallback(Handler.java:751)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                           at android.os.Looper.loop(Looper.java:154)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:6247)
                                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                                           at   com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)

2 个答案:

答案 0 :(得分:1)

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.animation.Animation.cancel()' on a null object reference at com.equiware.mickeyt.fire.CoreActivity$2.onSwipedDown(CoreActivity.java:161)

第161行似乎是:

WebShrink.cancel();

WebShrink可能是null

答案 1 :(得分:0)

您应该在onSwipeDown方法之外加载动画,也许您可​​以将其放在活动的onCreate中:

WebShrink = AnimationUtils.loadAnimation(CoreActivity.this,R.anim.m_webview_shrink);

然后在调用onSwipeDown之前将其实例化。