Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TransitionSet ArrayList.size() on a null object reference

Started realization for open images with Shared Elements and animation by this guide.

https://android-developers.googleblog.com/2018/02/continuous-shared-element-transitions.html

But catched an exception:

java.lang.NullPointerException: Attempt to invoke virtual method 'int java.util.ArrayList.size()' on a null object reference
at android.support.transition.TransitionSet.setDuration(TransitionSet.java:196)
at android.support.transition.TransitionSet.setDuration(TransitionSet.java:60)
at android.support.transition.Transition.<init>(Transition.java:278)
at android.support.transition.TransitionSet.<init>(TransitionSet.java:91)
at android.support.transition.TransitionInflater.createTransitionFromXml(TransitionInflater.java:151)
at android.support.transition.TransitionInflater.inflateTransition(TransitionInflater.java:70)

When call

TransitionInflater.from(context).inflateTransition(R.transition.my_transition)
like image 594
Merov Avatar asked Mar 24 '18 05:03

Merov


2 Answers

Found nothing on this problem from the Google, that why i post this.

Problem was in duration parameter.

You can fix it like this:

Need to remove duration from xml, and set it after TransitionSet created in code.

val transition = TransitionInflater.from(context).inflateTransition(R.transition.my_transition)
transition.duration = 325

Hope helped someone.

like image 158
Merov Avatar answered Oct 07 '22 00:10

Merov


In my case this error was happening because I had imported TransitionInflator from

import android.support.transition.TransitionInflater

While it should be imported from

import android.transition.TransitionInflater

When I fixed the import, the error got resolved.

like image 29
Anuj Garg Avatar answered Oct 06 '22 22:10

Anuj Garg