title: Making an animated background for an android app not working
body: <p>Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.widget.RelativeLayout.getBackground()' on a null object reference</p>
  
  <p>I am creating an android app and want to have an animated background for it.
  Unfortunatelly, I get this error here and I have no idea why it is so.</p>
  
  <p>Here is the XML that I have:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout
      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:id="@+id/myLayout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@drawable/my_bg_animate"
      tools:context=".AccessControlActivity"&gt;
  
      &lt;LinearLayout
           ..../&gt;
  
      &lt;TextView
          .... /&gt;
  
  
      &lt;ImageView
           .... /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Here is the java file/class:</p>
  
  <pre><code>    public class AccessControlActivity extends AppCompatActivity {
  
          ConstraintLayout myLayout;
  
  
          NfcAdapter nfcAdapter;
          Button btnPositive, btnNegative;
          Dialog epicDialog;
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              RelativeLayout relativeLayout = findViewById(R.id.myLayout);
              AnimationDrawable animationDrawable = (AnimationDrawable) relativeLayout.getBackground();
              animationDrawable.setEnterFadeDuration(4500);
              animationDrawable.setExitFadeDuration(4500);
              animationDrawable.start();
  
  
  
  
              }
  }
  </code></pre>
  
  <p>And that are the errors I see when I attempt to run the programm:</p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nfc.netvision/com.nfc.netvision.AccessControlActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.widget.RelativeLayout.getBackground()' on a null object reference
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
          at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
          at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
          at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
          at android.os.Handler.dispatchMessage(Handler.java:107)
          at android.os.Looper.loop(Looper.java:214)
          at android.app.ActivityThread.main(ActivityThread.java:7356)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
       Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.widget.RelativeLayout.getBackground()' on a null object reference
          at com.nfc.netvision.AccessControlActivity.onCreate(AccessControlActivity.java:37)
          at android.app.Activity.performCreate(Activity.java:7802)
          at android.app.Activity.performCreate(Activity.java:7791)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) 
          at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
          at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
          at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) 
          at android.os.Handler.dispatchMessage(Handler.java:107) 
          at android.os.Looper.loop(Looper.java:214) 
          at android.app.ActivityThread.main(ActivityThread.java:7356) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 
  </code></pre>
  
  <p>Thank you in advance! Looking forward to some answers!</p>