NullPointerException - Drawable.setBounds - probably due to fragment transitions

雨燕双飞 提交于 2019-12-12 08:47:19

问题


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.


回答1:


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)




回答2:


I followed answer made by @BladeCoder in this thread. His solution was just one part if you used Universal Image Loader.

After adding placeholder to ImageView, you need also to put some image or color (depends of your needs) to XML.



来源:https://stackoverflow.com/questions/31381385/nullpointerexception-drawable-setbounds-probably-due-to-fragment-transitions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!