I am using ValueAnimator to animate a View, but it throws a NullPointerException whenever I call start().
here is my stack trace after calling start() in my code:
java.lang.NullPointerException
at android.animation.ValueAnimator.initAnimation(ValueAnimator.java:447)
at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:495)
at android.animation.ValueAnimator.start(ValueAnimator.java:913)
at android.animation.ValueAnimator.start(ValueAnimator.java:923)
here is the part of my code that creates and calls animation:
ValueAnimator va = new ValueAnimator();
va.ofInt(somevalue, 0);
va.setDuration(Game.ANIMATION_DURATION);
va.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {//some code here
}
@Override
public void onAnimationEnd(Animator animation) {//some code here
}
@Override
public void onAnimationCancel(Animator animation) {}
@Override
public void onAnimationRepeat(Animator animation) {}
});
va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
//some code here
}
});
va.setInterpolator(new DecelerateInterpolator());
va.start();
I'm pretty sure the correct way to create an instance is like this:
ValueAnimator va = ValueAnimator.ofInt(someValue, 0);
. Theva.ofInt(...)
is doing nothing right now.