NullPointerException - Drawable.setBounds - 可能是由于片段转换 [英] NullPointerException - Drawable.setBounds - probably due to fragment transitions

查看:34
本文介绍了NullPointerException - Drawable.setBounds - 可能是由于片段转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误,但我不知道为什么(此错误非常罕见,对我来说无法重现):

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)

我认为这与 android FragmentActivity 转换有关,但我不确定...以上是完整的堆栈跟踪.

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

也许很有趣,我正在使用 support-library

Maybe interesting, I'm using the support-library

有没有人知道这是从哪里来的,我该如何预防?

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

编辑

如评论中所写:

  • 我不知道这个异常来自哪个代码块
  • 我自己不制作任何动画
  • 我认为,这个问题来自片段之间的事务(我在我的应用中使用的唯一动画)

EDIT2

我不知道我必须确保 ImageView 确实有内容.这可能会导致上述错误,ImageView 还没有图像.

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.

推荐答案

Fragment 或 Activity 过渡试图为没有可绘制集的 ImageView 设置动画.确保在使用 ChangeImageTransform 为 ImageView 设置动画(或禁用此类动画)时始终为 ImageView 设置 Drawable

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)

这篇关于NullPointerException - Drawable.setBounds - 可能是由于片段转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆