TransitionSet ArrayList.size() on a null object reference
Asked Answered
M

2

12

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)
Mathis answered 24/3, 2018 at 5:54 Comment(0)
M
28

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.

Mathis answered 24/3, 2018 at 5:54 Comment(2)
Looks like you were following this blog too. android-developers.googleblog.com/2018/02/… . Thanks for the help.Leathery
I wish I could upvote this 50X. That was such an annoying little bug. Note this can be shortened a bit using .apply{ duration = 325L }Arnuad
M
5

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.

Moffatt answered 14/8, 2018 at 9:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.