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)
Merov
  • 1,028
  • 1
  • 14
  • 29

2 Answers2

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.

Merov
  • 1,028
  • 1
  • 14
  • 29
  • 3
    Looks like you were following this blog too. https://android-developers.googleblog.com/2018/02/continuous-shared-element-transitions.html . Thanks for the help. – Sahil Patel Apr 04 '18 at 11:20
  • 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 }` – gMale Feb 01 '19 at 23:56
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.

Anuj Garg
  • 959
  • 10
  • 12