Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android java.lang.IllegalArgumentException: Invalid Transition types

Recently i have got java.lang.IllegalArgumentException: Invalid Transition types. This exception happens on android api 19 and it appeared after i have updated android build tools and support libraries to version 27.

Does anyone know what has changed with KitKat transitions?

    Fragment fragment = new  Fragment();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        Transition transition = new AutoTransition();
        fragment.setSharedElementEnterTransition(transition);
    }

    String backStateName = fragment.getClass().getName();
    FragmentManager manager = getFragmentManager();
    FragmentTransaction ft = manager.beginTransaction();
    ft.addSharedElement(view, "TransitionView");
    ft.replace(R.id.mainActivity_container, fragment, backStateName);
    ft.addToBackStack(backStateName);
    ft.commit();

Full exception:

Fatal Exception: java.lang.IllegalArgumentException: Invalid Transition types
   at android.support.v4.app.FragmentTransition.chooseImpl(FragmentTransition.java:461)
   at android.support.v4.app.FragmentTransition.configureTransitionsOrdered(FragmentTransition.java:3317)
   at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2380)
   at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2338)
   at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2245)
   at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:703)
   at android.os.Handler.handleCallback(Handler.java:733)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:136)
   at android.app.ActivityThread.main(ActivityThread.java:5590)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
   at dalvik.system.NativeStart.main(NativeStart.java)

UPDATE

After changing from if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) to if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) I don't get exception.

like image 753
Martynas Avatar asked Apr 13 '18 08:04

Martynas


2 Answers

You are mixing transitions from androidx (the support library) and the platform. For example.:

import androidx.transition.AutoTransition;
import android.transition.Fade;

(note the missing 'x')

Change that to only use support library, like this:

import androidx.transition.AutoTransition;
import androidx.transition.Fade;
like image 64
Jacob Nordfalk Avatar answered Sep 22 '22 13:09

Jacob Nordfalk


Looking at the change here it looks like it should probably read 'must' use support transitions rather than 'can' use them. Try changing your AutoTransition from android.transition.AutoTransition to android.support.transition.AutoTransition and it should work perfectly without needing any SDK version checks.

like image 36
user3265561 Avatar answered Sep 23 '22 13:09

user3265561