There is a TextView in which I want to display an array of numbers in turn. I tried this option but in my opinion it does not quite fit me. I want to do this using ObjectAnimator , in a similar way:

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_learn_result); tvCount = (TextView) findViewById(R.id.tv_count); int[] array = new int[] {1,2,3,4,5,6,7,8,9,10}; ObjectAnimator animator = new ObjectAnimator(); animator.ofInt(tvCount, "progress" ,array); animator.setDuration(6000); animator.start(); } 

But I get:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.MyActivity}: java.lang.NullPointerException: Attempt to get length of null array at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5422) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.NullPointerException: Attempt to get length of null array at android.animation.ValueAnimator.initAnimation(ValueAnimator.java:534) at android.animation.ObjectAnimator.initAnimation(ObjectAnimator.java:880) at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:610) at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:589) at android.animation.ValueAnimator.start(ValueAnimator.java:1106) at android.animation.ValueAnimator.start(ValueAnimator.java:1117) at android.animation.ObjectAnimator.start(ObjectAnimator.java:852) at com.attrakti.englishfor.activities.MyActivity.onCreate(LearnActivityResult.java:59) at android.app.Activity.performCreate(Activity.java:6251) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5422) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
  • show a full stack, and more code - specifically, where you initialize tvCount - Vladyslav Matviienko
  • @metalurgus is - Kirill Stoianov
  • Well, you never initialize tvCount . He ended up with you null - Vladyslav Matviienko
  • Sorry, I just removed too much from the code, tvCount initialized. the problem is the same. Tell me and so you can do? Maybe I specify the wrong name of the setter? - Kirill Stoianov
  • You have not shown what tvCount , and how and when you initialize it. - Vladyslav Matviienko

1 answer 1

Make through ValueAnimator :

  final TextView tvCount = (TextView)findViewById(R.id.tv_count); int[] array = new int[] {1,2,3,4,5,6,7,8,9,10}; ValueAnimator animator = ValueAnimator.ofInt(array); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { tvCount.setText(""+animation.getAnimatedValue()); } }); animator.setDuration(6000); animator.start(); 
  • great, what you need! - Kirill Stoianov