0

I've added Firebase into my Android Studio however I am getting an error:

W/PersistentConnection: pc_0 - Firebase Database connection was forcefully killed by the server. Will not attempt to reconnect. Reason: The database lives in a different region. Please change your database URL to https://destination-e6a01-default-rtdb.europe-west1.firebasedatabase.app"

I changed the region but nothing is happening In my app I have this in my java code:

// Initialize Firebase in your app
        FirebaseApp.initializeApp(this);

        // Create a reference to your Firebase Realtime Database instance using the URL
        FirebaseDatabase database = FirebaseDatabase.getInstance("https://Destination.firebaseio.com/");
        Log.d("TAG", "Database URL: " + database.getReference().toString());


        DatabaseReference myRef = database.getReference("destination-e6a01-default-rtdb");

        Spinner categorySpinner = findViewById(R.id.spinner_categories);
        String category = categorySpinner.getSelectedItem().toString();

        double latitude = 52.519345;
        double longitude = -6.610428;

        VanCameraLocations speedvancameralocations = new VanCameraLocations(latitude, longitude, category);

        myRef.push().setValue(speedvancameralocations);

I tried using this question however the answer for this question didn't work for me. My logcat is saying some information was uploaded to a database but the database I am using when I go look at my database online it doesn't show my database can anyone help me

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Donny
  • 3
  • 3

1 Answers1

0

You're getting the following error message:

Firebase Database connection was forcefully killed by the server. Will not attempt to reconnect. Reason: The database lives in a different region.

Because you're passing to the getInstance() method, the wrong URL:

FirebaseDatabase database = FirebaseDatabase.getInstance("https://Destination.firebaseio.com/");

The URL of your project is not:

https://Destination.firebaseio.com/

But:

https://destination-e6a01-default-rtdb.europe-west1.firebasedatabase.app

So to solve this, please change the database declaration to:

FirebaseDatabase database = FirebaseDatabase.getInstance("https://destination-e6a01-default-rtdb.europe-west1.firebasedatabase.app");

Besides that, please remove the following line of code:

//DatabaseReference myRef = database.getReference("destination-e6a01-default-rtdb");

Because the database URL should be passed to the getInstance() method and not the getReference() method. One more thing to mention is that when you pass an URL, you have to pass with the https:// not without it.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193