I have been stuck in the past week on connecting my project to a Firebase database. I watched many tutorials and followed the instructions step by step, and something goes wrong and the database doesn't connect:
package com.example.myapplication;
>imports
DatabaseReference databaseReference;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(MainActivity.this, "hi", Toast.LENGTH_SHORT).show();
databaseReference= FirebaseDatabase.getInstance().getReference("this is the path");
Toast.makeText(MainActivity.this, "hi2", Toast.LENGTH_SHORT).show();
databaseReference.setValue("here there").addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void unused) {
Toast.makeText(MainActivity.this, "1", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(MainActivity.this, "2", Toast.LENGTH_SHORT).show();
}
}).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Toast.makeText(MainActivity.this, "3", Toast.LENGTH_SHORT).show();
}
});
Toast.makeText(MainActivity.this, "bye", Toast.LENGTH_SHORT).show();
}
The code doesn't run through the getInstance for some reason.
"hi1", "hi2", and "bye" are the displayed toast.
The connection is set up perfectly but not established.
Any help would be extremely appreciated.