'data not inserting into firebase realtime database
The code executes without any error but firebase realtime database shows :-
testapp-a212c-default-rtdb: null
I have created the model class User. How do I insert data into firebase realtime database?
public class MainActivity extends AppCompatActivity {
private DatabaseReference mDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDatabase = FirebaseDatabase.getInstance().getReference();
writeNewUser("123","asdf","[email protected]");
}
public void writeNewUser(String userId, String name, String email) {
User user = new User(name, email);
mDatabase.child("users").child(userId).setValue(user);
}
Solution 1:[1]
To get a reference to a database other than a us-central1 default dstabase, you must pass the database URL to getInstance() (or Kotlin+KTX database()) . For a us-central1 default database, you can call getInstance() (or database) without arguments.
I was using SouthAsia Database.
Solution 2:[2]
In my case, I forgot to insert stream: FirebaseAuth.instance.onAuthStateChanged, in main.dart file. Which is ended up with uploading data to firebase Real Time Database.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gaurav Thapa |
| Solution 2 | Kai - Kazuya Ito |
