android - Data is not getting inserted inside the Firebase Database -
i have created database in firebase , rules set are:
{ "rules": { ".read": true, ".write": true } }
the format of database like:
fieldglass-aeca7 0 age: 23 name:"shikher" 1 age: 24 name:"samarth"
now want add record age:12 , name: xyz
i have written code in oncreate() function follows:
protected void oncreate(bundle savedinstancestate) { .............. firebasedatabase.getinstance().setpersistenceenabled(true); databasereference fg=firebasedatabase.getinstance().getreference("fieldglass-aeca7"); user u=new user(12,"shikhermishra"); string key=fg.push().getkey(); fg.child(key).setvalue(u); try { thread.sleep(2000); } catch (interruptedexception e) { e.printstacktrace(); } fg.addlistenerforsinglevalueevent(new valueeventlistener() { @override public void ondatachange(datasnapshot datasnapshot) { log.d("listener", "the data has changed"); } @override public void oncancelled(databaseerror databaseerror) { } });
my user class is:
public class user { public int age; public string name; public user(){ } public user(int age,string name) { this.name=name; this.age=age; } }
but values not getting inserted database.and there no error reported in log well.i have used functions mentioned in https://firebase.google.com/docs/database/android/read-and-write link of firebase provided. how can insert data database?
Comments
Post a Comment