1

I'm trying to follow a tutorial on using Firbase database and I'm not sure why why this is happening since this is my first time trying it.

I'm getting this exception in my app logcat.

03-09 02:39:57.373 15997-15997/com.example.android.clouddatabase E/AndroidRuntime: FATAL EXCEPTION: main
                                                                               Process: com.example.android.clouddatabase, PID: 15997
                                                                               java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.clouddatabase/com.example.android.clouddatabase.MainActivity}: java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist. 
                                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2491)
                                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2564)
                                                                                   at android.app.ActivityThread.access$800(ActivityThread.java:170)
                                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1441)
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:111)
                                                                                   at android.os.Looper.loop(Looper.java:194)
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:5576)
                                                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                                                   at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:955)
                                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:750)
                                                                                Caused by: java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist. 
                                                                                   at com.google.firebase.FirebaseApp.getInstance(Unknown Source)
                                                                                   at com.google.firebase.FirebaseApp.getInstance(Unknown Source)
                                                                                   at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
                                                                                   at com.example.android.clouddatabase.MainActivity.onCreate(MainActivity.java:46)
                                                                                   at android.app.Activity.performCreate(Activity.java:6041)
                                                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
                                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2437)
                                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2564) 
                                                                                   at android.app.ActivityThread.access$800(ActivityThread.java:170) 
                                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1441) 
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:111) 
                                                                                   at android.os.Looper.loop(Looper.java:194) 
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:5576) 
                                                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                                                   at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:955) 
                                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:750) 

This is my build.gradle app file looks like

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.android.clouddatabase"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.android.support:design:26.1.0'
    compile 'com.google.firebase:firebase-database:9.4.0'
    compile 'com.google.firebase:firebase-auth:9.4.0'
    compile 'com.google.firebase:firebase-core:9.4.0'
    compile 'com.android.support:recyclerview-v7:26.1.0'
    compile 'com.android.support:multidex:1.0.1'


}

I have tried a number of solutions but non of them seemed to work. so I'm open for any suggestions

salRad
  • 320
  • 1
  • 8
  • 21

1 Answers1

1

You forgot to add this to the end of your app level gradle file:

apply plugin: 'com.google.gms.google-services' 

Note that in your project level gradle file you should have:

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.2.0'


    }
}

It looks like you don't have a configuration file as well, here's how to download it.

Levi Moreira
  • 11,917
  • 4
  • 32
  • 46
  • OK and this may sound very elementary, but where should I put it, I tried putting it in the dependencies tag but I'm getting an error – salRad Mar 08 '18 at 23:56
  • right at the bottom of you grade file, the last thing in it – Levi Moreira Mar 08 '18 at 23:56
  • Error:Execution failed for task ':app:processDebugGoogleServices'. > File google-services.json is missing. The Google Services Plugin cannot function without it. Searched Location: D:\CloudDatabase\app\src\debug\google-services.json D:\CloudDatabase\app\google-services.json – salRad Mar 08 '18 at 23:57
  • it seems you didn't configure firebase properly. You need to configure it and download a configuration file called google-services.json – Levi Moreira Mar 08 '18 at 23:58
  • Thanks, I already downloaded the file but it seems to be in the wrong directory, I moved it now inside the app directory and waiting for the result. – salRad Mar 09 '18 at 00:02
  • THANKS!! it is working! I had to create a sub folder in the "app" folder and named it "debug" as proposed in the error message. – salRad Mar 09 '18 at 00:30