Android 具有机器人分子的AnimatorProxy中的Nineodeldroid NullPointerException

Android 具有机器人分子的AnimatorProxy中的Nineodeldroid NullPointerException,android,robolectric,nineoldandroids,Android,Robolectric,Nineoldandroids,我正在测试的视图有动画,当我使用Robolectric进行测试时,它似乎出了很大的问题。动画是一个简单的幻灯片,使用NineodelDroids实现兼容性。在Robolectric之外一切正常,但我的单元测试因空指针而崩溃: 10:34:35.419 [DEBUG] [TestEventLogger] java.lang.NullPointerException 10:34:35.419 [DEBUG] [TestEventLogger] at com.nineoldandro

我正在测试的视图有动画,当我使用Robolectric进行测试时,它似乎出了很大的问题。动画是一个简单的幻灯片,使用NineodelDroids实现兼容性。在Robolectric之外一切正常,但我的单元测试因空指针而崩溃:

10:34:35.419 [DEBUG] [TestEventLogger]     java.lang.NullPointerException
10:34:35.419 [DEBUG] [TestEventLogger]      at com.nineoldandroids.view.animation.AnimatorProxy.applyTransformation(AnimatorProxy.java:316)
10:34:35.419 [DEBUG] [TestEventLogger]      at android.view.animation.Animation.getTransformation(Animation.java:870)
10:34:35.420 [DEBUG] [TestEventLogger]      at org.robolectric.shadows.ShadowView$2.run(ShadowView.java:492)
10:34:35.420 [DEBUG] [TestEventLogger]      at org.robolectric.util.Scheduler.runOrQueueRunnable(Scheduler.java:218)
10:34:35.420 [DEBUG] [TestEventLogger]      at org.robolectric.util.Scheduler.postDelayed(Scheduler.java:73)
10:34:35.421 [DEBUG] [TestEventLogger]      at org.robolectric.shadows.ShadowChoreographer.postCallbackDelayed(ShadowChoreographer.java:44)
10:34:35.421 [DEBUG] [TestEventLogger]      at android.view.Choreographer.postCallbackDelayed(Choreographer.java)
10:34:35.427 [DEBUG] [TestEventLogger]      at org.robolectric.shadows.ShadowView.setAnimation(ShadowView.java:487)
10:34:35.429 [DEBUG] [TestEventLogger]      at android.view.View.setAnimation(View.java)
10:34:35.431 [DEBUG] [TestEventLogger]      at com.nineoldandroids.view.animation.AnimatorProxy.<init>(AnimatorProxy.java:66)
10:34:35.432 [DEBUG] [TestEventLogger]      at com.nineoldandroids.view.animation.AnimatorProxy.wrap(AnimatorProxy.java:38)
10:34:35.432 [DEBUG] [TestEventLogger]      at com.nineoldandroids.animation.PreHoneycombCompat$14.get(PreHoneycombCompat.java:161)
10:34:35.432 [DEBUG] [TestEventLogger]      at com.nineoldandroids.animation.PreHoneycombCompat$14.get(PreHoneycombCompat.java:153)
10:34:35.432 [DEBUG] [TestEventLogger]      at com.nineoldandroids.animation.PropertyValuesHolder.setupSetterAndGetter(PropertyValuesHolder.java:510)
10:34:35.433 [DEBUG] [TestEventLogger]      at com.nineoldandroids.animation.ObjectAnimator.initAnimation(ObjectAnimator.java:410)
10:34:35.433 [DEBUG] [TestEventLogger]      at com.nineoldandroids.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:538)
10:34:35.433 [DEBUG] [TestEventLogger]      at com.nineoldandroids.animation.ValueAnimator.start(ValueAnimator.java:928)
10:34:35.433 [DEBUG] [TestEventLogger]      at com.nineoldandroids.animation.ValueAnimator.start(ValueAnimator.java:951)
10:34:35.433 [DEBUG] [TestEventLogger]      at com.nineoldandroids.animation.ObjectAnimator.start(ObjectAnimator.java:385)
10:34:35.433 [DEBUG] [TestEventLogger]      at com.nineoldandroids.animation.AnimatorSet.start(AnimatorSet.java:502)
其中mView是
mView=newweakreference(视图)


如何从测试用例而不是我的应用程序代码中理想地解决这个问题,有什么建议吗?

似乎正在发生的是,在
AnimationProxy
完全初始化之前,UI/Main looper会执行为列表元素设置动画的NineodelAndRoid动画。这可能是由于在Robolectric 3中更好地模拟了Android线程体系结构

我打电话解决了这个问题:

ShadowLooper.pauseMainLooper()

将此调用放在任何可以在NineodelDroids中启动动画的方法之前

更新:

这给我带来了更多的麻烦,而上面的解决方法对于制作动画的每一段代码都很烦人,所以我对它进行了分叉和修复,非常小的改动:


太棒了,谢谢!很抱歉,我花了一段时间才回到这个问题:)
View view = mView.get();