Mistake:
Process: pc.dd.fragment_animation, PID: 22407 java.lang.IllegalArgumentException: Shared element must not be null ...at pc.dd.fragment_animation.MainClass$1.onClick(MainClass.java:91) Master Activation Xml:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="pc.dd.fragment_animation.MainClass"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="fill_parent" android:layout_height="200dp" android:transitionName="source2" android:id="@+id/source" android:layout_gravity="center_horizontal" android:src="@drawable/image1" android:scaleType="center" /> </LinearLayout> Activation code 2 on which we go after the animation:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="wrap_content" android:layout_height="200dp" android:id="@+id/image_target" android:layout_gravity="center_horizontal" android:transitionName="tar" android:src="@drawable/image1" android:scaleType="center" /> OnCreate code:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_class); final View photo = findViewById (R.id.image_target); final ImageView image = (ImageView) findViewById(R.id.source); image.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainClass.this, Second_Activity.class); intent.setAction(intent.ACTION_VIEW); intent.putExtra(MainClass.this.EXTRA_PHOTO, R.drawable.image1); //String transitionName = (String) findViewById(R.id.image_target); startActivity(intent, ActivityOptions.makeSceneTransitionAnimation( MainClass.this, photo , "tar" ).toBundle()); } }); What is wrong, can not understand?