-2

So I'm using the library Swipe by Pwittchen and the code being used is this section:

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
            }
        }

Currently I crashes if you swipe down in the moment it is created. Im trying to find a way around it with:

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

but this is not working and am wondering if anyone could help me with this. the ideal situation is that if the toolbar is visible or if WebShrink is already in place then do nothing but I can't find away around it

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)
EquiWare
  • 127
  • 2
  • 14

2 Answers2

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)

Line 161 seems to be:

WebShrink.cancel();

WebShrink is probably null.

kabuko
  • 36,028
  • 10
  • 80
  • 93
  • what can I use instead of .cancel() – EquiWare Jan 19 '18 at 02:15
  • You should check to see if `WebShrink` is null before using it. Read this related question/answer: https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it/218510#218510 – kabuko Jan 19 '18 at 02:21
0

You should load the animation outside onSwipeDown method, maybe you can place this in the activity's onCreate:

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

Then it will be instantiated before onSwipeDown is called.

Juan Cruz Soler
  • 8,172
  • 5
  • 41
  • 44