9

I've been working on an existing codebase for a while and from browsing our crash log service I've noticed an exception that happens pretty frequently, I am not able to reproduce this issue, nor do I have the context for the scenario to try and dig in, as this is a pretty big project it has become increasingly hard to find out the cause of this exception.

I have been searching online for similar issues and couldn't find any useful information. If anyone is familiar with this issue, your help would be greatly appreciated.

Stacktrace is as follows:

java.lang.NullPointerException
   at android.animation.PropertyValuesHolder.setupSetterAndGetter(PropertyValuesHolder.java:505)
   at android.animation.ObjectAnimator.initAnimation(ObjectAnimator.java:487)
   at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:517)
   at android.animation.ValueAnimator.start(ValueAnimator.java:936)
   at android.animation.ValueAnimator.start(ValueAnimator.java:946)
   at android.animation.ObjectAnimator.start(ObjectAnimator.java:465)
   at android.animation.AnimatorSet$1.onAnimationEnd(AnimatorSet.java:579)
   at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1056)
   at android.animation.ValueAnimator.access$400(ValueAnimator.java:50)
   at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:644)
   at android.animation.ValueAnimator$AnimationHandler.run(ValueAnimator.java:660)
   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
   at android.view.Choreographer.doCallbacks(Choreographer.java:574)
   at android.view.Choreographer.doFrame(Choreographer.java:543)
   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
   at android.os.Handler.handleCallback(Handler.java:733)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:136)
   at android.app.ActivityThread.main(ActivityThread.java:5105)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
   at dalvik.system.NativeStart.main(NativeStart.java)

Cheers.

nurealam11
  • 537
  • 4
  • 16
woot
  • 3,671
  • 4
  • 26
  • 39

7 Answers7

6

The issue turned out to be an animation being invoked from a Handler using postDelayed(), which eventually resulted in attempting to animate a null View reference, since it wasn't cleared properly according to it's host lifecycle events.

woot
  • 3,671
  • 4
  • 26
  • 39
  • I also run into this problem. Yet I don't know which animation results in this crash. Could you please tell me how you started your animation to create a stack trace like this? Thanks. (I mean, I know the target should be null. But beside that, how is the animation created & started to be run in Choreographer$FrameDisplayEventReceiver.run?) – DenMark Oct 29 '14 at 08:47
  • Yeah if the view is null this is the error. My anims worked on one device but not another and the answer was slightly different layout xml files. Doh! – Daniel Wilson Jul 29 '16 at 11:20
  • so how to prevent it? we can not remove the `Handler` – Linh Jun 20 '17 at 02:38
  • so what is the solution? i use handler with post method , i use it because i need to animate round progress Bar(some reason progress bar not animated on main thread), i have the same problem on some devices with API-19 – Pavel Poley Jul 14 '17 at 12:21
5

maybe you tagret is null, print log with animatorSet.getTarget() to see

Raul Yang
  • 61
  • 1
  • 2
  • @Raul's answer is valid. NPE can occur also when the target is not set (i.e. null). Please remove your downvotes. – Ognyan Jan 12 '16 at 13:57
2

I also get this stack trace when I use : ObjectAnimator animator = ObjectAnimator.ofFloat(this, "scale", 1); .... animator.start()

run in android 4.0.X, but it's ok for higher version, you can also refer this guy's commit, though I don't how to fix, however this is the root cause definitely.

jiangyan.lily
  • 932
  • 1
  • 8
  • 16
  • Finally, I find out that, there is not a property called "scale", this is the root cause that crash on android 4.0.x, but fine on 5.0 I use this way http://stackoverflow.com/questions/4946295/android-expand-collapse-animation to achieve the same animation, it works perfect, hope this can help you. – jiangyan.lily Dec 15 '15 at 10:47
0

I went through this exception now and find out that I was getting the instance of the View with animation from getActivity().findViewById. While being in a fragment I had to instantiate it from the rootview inflated containing the view.

I basically moved the view from the Activity to the Fragment layout, but didn't change the code. So the rootview.findViewById resolved my problem.

My stacktrace:

java.lang.NullPointerException
    at android.animation.PropertyValuesHolder.setupSetterAndGetter(PropertyValuesHolder.java:505)
    at android.animation.ObjectAnimator.initAnimation(ObjectAnimator.java:392)
    at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:495)
    at android.animation.ValueAnimator.start(ValueAnimator.java:913)
    at android.animation.ValueAnimator.start(ValueAnimator.java:923)
    at android.animation.ObjectAnimator.start(ObjectAnimator.java:370)
    at eu.davidea.passwordcloud.ui.ItemDetailFragment$3.onClick(ItemDetailFragment.java:162)
    at android.view.View.performClick(View.java:4084)
    at android.view.View$PerformClick.run(View.java:16966)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4745)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)
Davideas
  • 3,226
  • 2
  • 33
  • 51
0

Trust me, I found the solution of this crash issue on 4.0.x devices.

The problem is when you use ObjectAnimator without 'start' and 'end' value, the api on 4.0.x devices can't find the 'start' value to implement.

For example, this will lead to crash on 4.0.x devices

int endRadiusValue = 10;
ObjectAnimator
        .ofFloat(roundedGradientDrawable, "cornerRadius", endRadiusValue)
        .setDuration(200)
        .start();

And this code work perfect on all api level devices

int startRadiusValue = 0;
int endRadiusValue = 10;
ObjectAnimator
        .ofFloat(roundedGradientDrawable, "cornerRadius", startRadiusValue, endRadiusValue)
        .setDuration(200)
        .start();
Daniel Deng
  • 345
  • 1
  • 4
  • 8
0

The reason is the target view is null. ObjectAnimator ofFloat(Object target, ...).
This crash will only throw in 4x device.
There is no crash in another device

Linh
  • 57,942
  • 23
  • 262
  • 279
-1

enter image description here

I solve the problem by adding the animation to a animationSet just like this:

nvoigt
  • 75,013
  • 26
  • 93
  • 142
  • 1
    Please **[edit]** your post and show the actual code as text instead of screenshots. Others can't copy and paste from your images. [See here](https://meta.stackoverflow.com/a/285557/1402846) for details. Thank you. – Pang Apr 24 '17 at 02:32