1

I know this question has been asked before, but I've tried just about every posted solution and have been unsuccessful. I set up my Firebase realtime database with the Firebase documentation and followed everything properly. I set read and write values both to true (only for testing; will change later). This is my code:

package com.example.classfinder;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

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

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // init commit

        FirebaseDatabase.getInstance().getReference().child("name").push().setValue("hello, world!");

    }
}

I know my Gradle files are good since I followed the documentation to the dot and did my research. When I write to the database, nothing shows up. Let me know if you need more info to answer this question. Thanks!!

EDIT 1: IMAGE OF DATABASE: enter image description here

EDIT 2: Resolved by turning of wifi and using mobile data instead.

jbcallv
  • 21
  • 5
  • Show us how you check that nothing shows up. – Alex Mamo Mar 12 '21 at 14:02
  • I just go to the firebase realtime database site and I don't see a new child node... – jbcallv Mar 12 '21 at 14:22
  • Show us a screenshot of it. Besides that, have you tried to attach a listener to the setValue() operation, to see if something is wrong? – Alex Mamo Mar 12 '21 at 14:32
  • I have not tried a listener. How do I do this? I edited the original post to show the database – jbcallv Mar 12 '21 at 14:49
  • I don't see your database. Besides that, call `addOnCompleteListener()` on `.setValue("hello, world!")`. – Alex Mamo Mar 12 '21 at 14:55
  • I can't put the picture up since it's greater than 2 mib :/. Sorry, I'm new to stack overflow :'( – jbcallv Mar 12 '21 at 15:23
  • after set value you should attack addInCompleteListerner() and in this function object of Task will give you the reason , or you can simply use onSuccessListere() as well as onFailureListener() – Muhammad Farhan Arif Mar 12 '21 at 15:59
  • 1
    For an example of how to detect errors in the `setValue` call, see: https://gist.github.com/puf/4a94a01e3c2510298ee46d0a7f90ab75 – Frank van Puffelen Mar 12 '21 at 16:09
  • Thanks, I put the picture of the database in there now. Where do I find those error messages after running it? – jbcallv Mar 12 '21 at 16:44
  • I just added the listener. I am using log.v to tell me if !task.isSuccesful and it never enters that conditional. What can I do? – jbcallv Mar 12 '21 at 17:33

1 Answers1

0

Here is the solution, probably. Worked for me, if you used a database in a different region, you need to specify that in google-services.json

Firebase Database connection was forcefully killed by the server: Different region #flutter

Duje1
  • 1
  • 1
  • 2