1

I am trying to push data to Firebase Realtime Database, and I am currently using Firebase's official documentation. While following the guide halfway with their code, I encountered this error:

Cannot resolve symbol 'put'

Can someone offer some guidance as to why this is happening?

I have read some other questions from these places on StackOverflow, and I've even watched YouTube videos that talks about pushing data to Firebase.

Those resources either result in syntax errors and leave me with a dead end.

I've tried the following resources:

Post data from fragment to firebase

Can't save data to firebase database

How to save data on Firebase?

https://www.youtube.com/watch?v=MeYmSdU_bOY

These are my lines of code, that I've grabbed from Firebase's official documentation:

package sg.edu.singaporetech.teamproject;

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

import java.util.HashMap;
import java.util.Map;

public static class User {
    final FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference ref = database.getReference("server/saving-data/fireblog");

    public String date_of_birth;
    public String full_name;
    public String nickname;

    public User(String dateOfBirth, String fullName) {
        // ...
    }

    public User(String dateOfBirth, String fullName, String nickname) {
        // ...
    }


    DatabaseReference usersRef = ref.child("users");

    Map<String, User> users = new HashMap<>();
    users.put("alanisawesome",new User("June 23, 1912","Alan Turing"));
    users.put("gracehop",new User("December 9, 1906","Grace Hopper"));
    usersRef.setValueAsync(users);

}

Jim Ng
  • 91
  • 1
  • 4
  • 15

0 Answers0