title: Android Studio - MainActivity.java can't see id attributes
body: <p>I gave an id attribute: 
  android: id="@+id/animation_layout"<br>
  in the default layout (numbered as 1) in the activity_main.xml</p>
  
  <p>But when I tried to call it in the MainActivity.java by its id:
  ConstraintLayout constraintLayout = findViewById(R.id.animation_layout); </p>
  
  <ul>
  <li>It won't find it  (numbered as 2)</li>
  </ul>
  
  <p>What am I missing?</p>
  
  <p><a href="https://i.stack.imgur.com/R4WVU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R4WVU.png" alt="enter image description here"></a></p>
  
  <p>also attached the code:</p>
  
  <pre><code>&lt;android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:id="@+id/animation_layout"
  android:background="@drawable/gradients_list"
  tools:context=".MainActivity"&gt;
  </code></pre>
  
  <p>and the Java code:</p>
  
  <pre><code>    @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      //Gradient animation
  
      ConstraintLayout constraintLayout = findViewById(R.id.animation_layout);
      AnimationDrawable  animationDrawable = (AnimationDrawable) constraintLayout.getBackground();
      animationDrawable.setEnterFadeDuration(2000);
      animationDrawable.setEnterFadeDuration(4000);
      animationDrawable.start();
  </code></pre>
  
  <p>Thank you for helping :)</p>