NullPointerException в AnimatorSet.start на Android 4.4 - PullRequest
0 голосов
/ 04 января 2019

Я пытаюсь запустить анимацию с помощью ObjectAnimator и AnimatorSet. Код отлично работает на Версии> = Android 5.0, но выдает исключение NullPointerException на Kitkat 4.4

 Caused by: 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.start(AnimatorSet.java:563)

Вот фрагмент кода:

public void playAnimation(Button doneButton, AnimatorEndListener endListener) {
     long animDuration = 880; 
     ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(bottomContentControllers, "alpha", 1f, 0f);
     float value = (float)(0 - doneButton.getHeight() - doneButton.getTop());
     final ObjectAnimator slideUpDoneButton = ObjectAnimator.ofFloat(doneButton, "translationY",0f, value);
     final AnimatorSet animSet = new AnimatorSet();
     alphaAnimator.setDuration(animDuration);
     slideUpDoneButton.setDuration(animDuration);
     animSet.playTogether(alphaAnimator, slideUpDoneButton);
     if(endListener != null) {
        animSet.addListener(endListener);
     }
     animSet.start();
    }

1 Ответ

0 голосов
/ 08 января 2019

Решено! Каким-то образом Целевое представление bottomContentControllers в строке:

ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(bottomContentControllers, "alpha", 1f, 0f);

в какой-то момент кода получал Nullified. Удостоверился, что он никогда не получает Null, и добавил проверку Null, чтобы заставить его работать.

...