florent37 / ViewAnimator

A fluent Android animation library
Apache License 2.0
2.71k stars 423 forks source link

Null pointer Exception when combining fadein and fadeout animation #37

Open bitsydarel opened 6 years ago

bitsydarel commented 6 years ago

Hi, trying to animate by button with the following code but getting null exception not from my code but from internal code.

ViewAnimator.animate(binding.liveFavorite) .zoomIn() .fadeOut() .custom(AnimationListener.Update { view, _ -> view.setImageResource(R.drawable.ic_bookmarked) } ) .fadeIn() .zoomOut() .start()

Stacktrace:

FATAL EXCEPTION: main Process: com.dbeginc.dbweather, PID: 5806 java.lang.NullPointerException: Attempt to get length of null array at android.animation.ValueAnimator.initAnimation(ValueAnimator.java:534) at android.animation.ValueAnimator.startAnimation(ValueAnimator.java:1263) at android.animation.ValueAnimator.access$100(ValueAnimator.java:67) at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:724) at android.animation.ValueAnimator$AnimationHandler$1.run(ValueAnimator.java:801) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:896) at android.view.Choreographer.doCallbacks(Choreographer.java:698) at android.view.Choreographer.doFrame(Choreographer.java:630) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:882) at android.os.Handler.handleCallback(Handler.java:815) at android.os.Handler.dispatchMessage(Handler.java:104) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main(ActivityThread.java:5795) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:768)

RahulSDeshpande commented 6 years ago

Hey @bitsydarel !!

I initially thought that the reason is the anonymous inner-type class in custom(--) method. But I was wrong.

The reason is the 2nd parameter of the custom(-,-...) method is float... values; i.e., it is expecting the valueAnimator float array values which you are not passing & is thus erroring out in your animation with Attempt to get length of null array.. exception.

Let us know if this fixes your issue :)

Cheers 👍