title: How to fix java.lang.RuntimeException on Android Studio?
body: <p>I'm trying to retrieve the registration token from my device using Firebase in an app which has a TextView that has as a purpose to contain the value of the token in it, when running the app everytime i get a java.lang.RuntimeException error, i added this code <code>FirebaseApp.initializeApp(this);</code> as instructed but i still get such error, i'm quite new to Android Studio and Firebase and i'm still experimenting.</p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>package com.gci.gestioncapteursincendie;
  
  import android.support.annotation.NonNull;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.webkit.WebSettings;
  import android.webkit.WebView;
  import android.widget.TextView;
  
  import com.google.android.gms.tasks.OnCompleteListener;
  import com.google.android.gms.tasks.Task;
  import com.google.firebase.FirebaseApp;
  import com.google.firebase.iid.FirebaseInstanceId;
  import com.google.firebase.iid.InstanceIdResult;
  
  public class MainActivity extends AppCompatActivity {
  
      private TextView textView;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          FirebaseApp.initializeApp(this);
  
          textView= findViewById(R.id.textViewToken);
          FirebaseInstanceId.getInstance().getInstanceId()
                  .addOnCompleteListener(new OnCompleteListener&lt;InstanceIdResult&gt;() {
                      @Override
                      public void onComplete(@NonNull Task&lt;InstanceIdResult&gt; task) {
                        if(task.isSuccessful()){
                            String token = task.getResult().getToken();
                            textView.setText("Token : " + token);
                          }
                          else
                        {
                            textView.setText("Token Not Generated");
                        }
                      }
                  });
      }
  
  }
  </code></pre>
  
  <p><strong>Log Trace:</strong></p>
  
  <pre><code>03-31 19:10:19.203 11562-11562/com.gci.gestioncapteursincendie E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.gci.gestioncapteursincendie, PID: 11562
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gci.gestioncapteursincendie/com.gci.gestioncapteursincendie.MainActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.gci.gestioncapteursincendie. Make sure to call FirebaseApp.initializeApp(Context) first.
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3319)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
          at android.app.ActivityThread.access$1100(ActivityThread.java:229)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:148)
          at android.app.ActivityThread.main(ActivityThread.java:7406)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
       Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.gci.gestioncapteursincendie. Make sure to call FirebaseApp.initializeApp(Context) first.
          at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@16.0.1:219)
          at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source)
          at com.gci.gestioncapteursincendie.MainActivity.onCreate(MainActivity.java:41)
          at android.app.Activity.performCreate(Activity.java:6904)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415) 
          at android.app.ActivityThread.access$1100(ActivityThread.java:229) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821) 
          at android.os.Handler.dispatchMessage(Handler.java:102) 
          at android.os.Looper.loop(Looper.java:148) 
          at android.app.ActivityThread.main(ActivityThread.java:7406) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
  </code></pre>
  
  <p><strong>build.gradle</strong></p>
  
  <pre><code>// Top-level build file where you can add configuration options common to all sub-projects/modules.
  
  buildscript {
      repositories {
          google()
          jcenter()
          maven {
              url 'https://maven.fabric.io/public'
          }
  
      }
      dependencies {
          classpath 'com.android.tools.build:gradle:3.3.2'
          classpath 'com.google.gms:google-services:4.1.0'
          classpath 'io.fabric.tools:gradle:1.26.1'
  
  
          // NOTE: Do not place your application dependencies here; they belong
          // in the individual module build.gradle files
      }
  }
  
  allprojects {
      repositories {
          google()
          jcenter()
  
      }
  }
  
  task clean(type: Delete) {
      delete rootProject.buildDir
  }
  </code></pre>