Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NullPointerException - Drawable.setBounds - probably due to fragment transitions

I'm getting following error and I don't know why (this error is VERY RARE and not reproducable for me):

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.drawable.Drawable.setBounds(int, int, int, int)' on a null object reference
at android.widget.ImageView.animateTransform(ImageView.java:1126)
at android.transition.ChangeImageTransform$2.set(ChangeImageTransform.java:64)
at android.transition.ChangeImageTransform$2.set(ChangeImageTransform.java:61)
at android.animation.PropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:938)
at android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:952)
at android.animation.ValueAnimator.animationFrame(ValueAnimator.java:1207)
at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1248)
at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:659)
at android.animation.ValueAnimator$AnimationHandler.run(ValueAnimator.java:682)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:549)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5321)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)

I think it has to do with the android Fragment and Activity transitions, but I'm not sure... The above is the complete stacktrace.

Maybe interesting, I'm using the support-library

Does anyone have an idea where this comes from and how I can prevent it?

EDIT

As written in the comments:

  • I don't know from which code block this exception comes from
  • I don't animate anything myself
  • I assume, this problem comes from transactions between fragments (the only animations I use in my app)

EDIT2

I did not know that I have to make sure an ImageView does have a content. This may lead to the above error, an ImageView that does not have an image yet.

like image 841
prom85 Avatar asked Jul 13 '15 10:07

prom85


1 Answers

A Fragment or Activity transition is trying to animate an ImageView which has no drawable set. Ensure you always have a Drawable set for your ImageView when you animate it with ChangeImageTransform (or disable this kind of animation)

like image 71
BladeCoder Avatar answered Sep 21 '22 05:09

BladeCoder