Error connecting Firebase to Android Studio Porject

I tried to link the connection firebase to android studio in my app. However, i can’t seem to run the application even though there is no coding error. I’ll provide the code below.

below is the java code.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>package com.example.rwn;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class ReportActivity extends AppCompatActivity {
private EditText editTextName, editTextBinLocation, editTextProblem;
private Button buttonSubmit;
private DatabaseReference databaseReference;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_report);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
// Initialize Firebase Database
databaseReference = FirebaseDatabase.getInstance().getReference("reports");
// Initialize UI elements
editTextName = findViewById(R.id.editTextName);
editTextBinLocation = findViewById(R.id.editTextBinLocation);
editTextProblem = findViewById(R.id.editTextProblem);
buttonSubmit = findViewById(R.id.buttonSubmit);
// Set onClick listener for the submit button
buttonSubmit.setOnClickListener(v -> submitReport());
}
private void submitReport() {
String name = editTextName.getText().toString().trim();
String binLocation = editTextBinLocation.getText().toString().trim();
String problem = editTextProblem.getText().toString().trim();
if (name.isEmpty() || binLocation.isEmpty() || problem.isEmpty()) {
Toast.makeText(this, "Please fill all fields", Toast.LENGTH_SHORT).show();
return;
}
String id = databaseReference.push().getKey();
Report report = new Report(id, name, binLocation, problem);
assert id != null;
databaseReference.child(id).setValue(report)
.addOnSuccessListener(aVoid -> {
Toast.makeText(this, "Report submitted", Toast.LENGTH_SHORT).show();
// Clear fields after submission
editTextName.setText("");
editTextBinLocation.setText("");
editTextProblem.setText("");
})
.addOnFailureListener(e -> Toast.makeText(this, "Failed to submit report", Toast.LENGTH_SHORT).show());
}
}
</code>
<code>package com.example.rwn; import android.os.Bundle; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import androidx.activity.EdgeToEdge; import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.FirebaseDatabase; public class ReportActivity extends AppCompatActivity { private EditText editTextName, editTextBinLocation, editTextProblem; private Button buttonSubmit; private DatabaseReference databaseReference; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); EdgeToEdge.enable(this); setContentView(R.layout.activity_report); ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); return insets; }); // Initialize Firebase Database databaseReference = FirebaseDatabase.getInstance().getReference("reports"); // Initialize UI elements editTextName = findViewById(R.id.editTextName); editTextBinLocation = findViewById(R.id.editTextBinLocation); editTextProblem = findViewById(R.id.editTextProblem); buttonSubmit = findViewById(R.id.buttonSubmit); // Set onClick listener for the submit button buttonSubmit.setOnClickListener(v -> submitReport()); } private void submitReport() { String name = editTextName.getText().toString().trim(); String binLocation = editTextBinLocation.getText().toString().trim(); String problem = editTextProblem.getText().toString().trim(); if (name.isEmpty() || binLocation.isEmpty() || problem.isEmpty()) { Toast.makeText(this, "Please fill all fields", Toast.LENGTH_SHORT).show(); return; } String id = databaseReference.push().getKey(); Report report = new Report(id, name, binLocation, problem); assert id != null; databaseReference.child(id).setValue(report) .addOnSuccessListener(aVoid -> { Toast.makeText(this, "Report submitted", Toast.LENGTH_SHORT).show(); // Clear fields after submission editTextName.setText(""); editTextBinLocation.setText(""); editTextProblem.setText(""); }) .addOnFailureListener(e -> Toast.makeText(this, "Failed to submit report", Toast.LENGTH_SHORT).show()); } } </code>
package com.example.rwn;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

public class ReportActivity extends AppCompatActivity {

    private EditText editTextName, editTextBinLocation, editTextProblem;
    private Button buttonSubmit;
    private DatabaseReference databaseReference;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_report);

        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        // Initialize Firebase Database
        databaseReference = FirebaseDatabase.getInstance().getReference("reports");

        // Initialize UI elements
        editTextName = findViewById(R.id.editTextName);
        editTextBinLocation = findViewById(R.id.editTextBinLocation);
        editTextProblem = findViewById(R.id.editTextProblem);
        buttonSubmit = findViewById(R.id.buttonSubmit);

        // Set onClick listener for the submit button
        buttonSubmit.setOnClickListener(v -> submitReport());
    }

    private void submitReport() {
        String name = editTextName.getText().toString().trim();
        String binLocation = editTextBinLocation.getText().toString().trim();
        String problem = editTextProblem.getText().toString().trim();

        if (name.isEmpty() || binLocation.isEmpty() || problem.isEmpty()) {
            Toast.makeText(this, "Please fill all fields", Toast.LENGTH_SHORT).show();
            return;
        }

        String id = databaseReference.push().getKey();
        Report report = new Report(id, name, binLocation, problem);

        assert id != null;
        databaseReference.child(id).setValue(report)
                .addOnSuccessListener(aVoid -> {
                    Toast.makeText(this, "Report submitted", Toast.LENGTH_SHORT).show();
                    // Clear fields after submission
                    editTextName.setText("");
                    editTextBinLocation.setText("");
                    editTextProblem.setText("");
                })
                .addOnFailureListener(e -> Toast.makeText(this, "Failed to submit report", Toast.LENGTH_SHORT).show());
    }
}

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>package com.example.rwn;
public class Report {
private String id;
private String name;
private String binLocation;
private String problem;
public Report() {
// Default constructor required for calls to DataSnapshot.getValue(Report.class)
}
public Report(String id, String name, String binLocation, String problem) {
this.id = id;
this.name = name;
this.binLocation = binLocation;
this.problem = problem;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getBinLocation() {
return binLocation;
}
public String getProblem() {
return problem;
}
}
</code>
<code>package com.example.rwn; public class Report { private String id; private String name; private String binLocation; private String problem; public Report() { // Default constructor required for calls to DataSnapshot.getValue(Report.class) } public Report(String id, String name, String binLocation, String problem) { this.id = id; this.name = name; this.binLocation = binLocation; this.problem = problem; } public String getId() { return id; } public String getName() { return name; } public String getBinLocation() { return binLocation; } public String getProblem() { return problem; } } </code>
package com.example.rwn;

public class Report {
    private String id;
    private String name;
    private String binLocation;
    private String problem;

    public Report() {
        // Default constructor required for calls to DataSnapshot.getValue(Report.class)
    }

    public Report(String id, String name, String binLocation, String problem) {
        this.id = id;
        this.name = name;
        this.binLocation = binLocation;
        this.problem = problem;
    }

    public String getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getBinLocation() {
        return binLocation;
    }

    public String getProblem() {
        return problem;
    }
}

let me know if i need to provide more context/code

I modified the gradle code to suit my project needs. I also added a line to connect to the internet in the manifest.xml file below is the gradle code.

(project level)

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:8.0.0") // Use the latest stable version
classpath("com.google.gms:google-services:4.3.10")
}
}
plugins {
// Use the latest stable version of the Android Application plugin and Google Services plugin
id("com.android.application") version "8.0.0" apply false
id("com.google.gms.google-services") version "4.3.10" apply false
}
allprojects {
repositories {
google()
mavenCentral()
}
}
</code>
<code>// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() mavenCentral() } dependencies { classpath("com.android.tools.build:gradle:8.0.0") // Use the latest stable version classpath("com.google.gms:google-services:4.3.10") } } plugins { // Use the latest stable version of the Android Application plugin and Google Services plugin id("com.android.application") version "8.0.0" apply false id("com.google.gms.google-services") version "4.3.10" apply false } allprojects { repositories { google() mavenCentral() } } </code>
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:8.0.0") // Use the latest stable version
        classpath("com.google.gms:google-services:4.3.10")
    }
}

plugins {
    // Use the latest stable version of the Android Application plugin and Google Services plugin
    id("com.android.application") version "8.0.0" apply false
    id("com.google.gms.google-services") version "4.3.10" apply false
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

(app level)

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>plugins {
id("com.android.application")
id("com.google.gms.google-services")
}
android {
namespace = "com.example.rwn"
compileSdk = 34
defaultConfig {
applicationId = "com.example.rwn"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled = true
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
dependencies {
implementation(platform("com.google.firebase:firebase-bom:33.0.0"))
implementation("androidx.multidex:multidex:2.0.1")
implementation("androidx.appcompat:appcompat:1.4.0")
implementation("com.google.android.material:material:1.4.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.3")
implementation("androidx.activity:activity:1.4.0")
implementation("com.google.firebase:firebase-analytics")
implementation("com.google.firebase:firebase-database")
implementation("com.github.denzcoskun:ImageSlideShow:0.0.6")
implementation("com.github.PhilJay:MPAndroidChart:v3.1.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.3")
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
}
</code>
<code>plugins { id("com.android.application") id("com.google.gms.google-services") } android { namespace = "com.example.rwn" compileSdk = 34 defaultConfig { applicationId = "com.example.rwn" minSdk = 24 targetSdk = 34 versionCode = 1 versionName = "1.0" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" multiDexEnabled = true } buildTypes { release { isMinifyEnabled = false proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") } } compileOptions { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } } dependencies { implementation(platform("com.google.firebase:firebase-bom:33.0.0")) implementation("androidx.multidex:multidex:2.0.1") implementation("androidx.appcompat:appcompat:1.4.0") implementation("com.google.android.material:material:1.4.0") implementation("androidx.constraintlayout:constraintlayout:2.1.3") implementation("androidx.activity:activity:1.4.0") implementation("com.google.firebase:firebase-analytics") implementation("com.google.firebase:firebase-database") implementation("com.github.denzcoskun:ImageSlideShow:0.0.6") implementation("com.github.PhilJay:MPAndroidChart:v3.1.0") testImplementation("junit:junit:4.13.2") androidTestImplementation("androidx.test.ext:junit:1.1.3") androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0") } </code>
plugins {
    id("com.android.application")
    id("com.google.gms.google-services")
}

android {
    namespace = "com.example.rwn"
    compileSdk = 34

    defaultConfig {
        applicationId = "com.example.rwn"
        minSdk = 24
        targetSdk = 34
        versionCode = 1
        versionName = "1.0"
        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled = true
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
        }
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation(platform("com.google.firebase:firebase-bom:33.0.0"))
    implementation("androidx.multidex:multidex:2.0.1")
    implementation("androidx.appcompat:appcompat:1.4.0")
    implementation("com.google.android.material:material:1.4.0")
    implementation("androidx.constraintlayout:constraintlayout:2.1.3")
    implementation("androidx.activity:activity:1.4.0")
    implementation("com.google.firebase:firebase-analytics")
    implementation("com.google.firebase:firebase-database")
    implementation("com.github.denzcoskun:ImageSlideShow:0.0.6")
    implementation("com.github.PhilJay:MPAndroidChart:v3.1.0")
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.1.3")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật