Situation: I'm trying to retrieve a string from the key "title" under the first push key (most recent object) inside my Realtime Database, but I keep getting "null".
MainActivity.java
...
mDatabaseReference.limitToFirst(1).addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
ExecutiveOrder executiveOrder = snapshot.getValue(ExecutiveOrder.class);
Log.i("MainActivity", "Title: " + executiveOrder.getTitle());
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
Log.e("Executive Order", "The read failed: " + databaseError.getDetails());
}
});
...
ExecutiveOrder.java
package com.example.cleeg.part;
import com.google.firebase.database.IgnoreExtraProperties;
#IgnoreExtraProperties
public class ExecutiveOrder {
private String mTitle;
private String mDate;
private String mSummary;
private String mText;
// Default constructor
public ExecutiveOrder() {}
public ExecutiveOrder(String title, String date, String text) {
mTitle = title;
mDate = date;
mText = text;
}
public String getTitle() { return mTitle; }
public String getDate() { return mDate; }
public String getSummary() { return mSummary; }
public String getText() { return mText; }
}
UPDATE: The problem was that I didn't have setters in my ExecutiveOrder.java
There are couple of changes to be done. It worked fine to me on very similar DB structure:
mDatabaseReference definition should not include "Executive Branch", because the branch is actually the value to be returned as object
of executiveOrder
I would recommend to change ValueEventListener to ChildEventListener, and update #Override methods accordingly (the names of the methods are slightly different).
I updated you code with needed changes - it should work. Please try. Well... as I can't test it on exact same DB, it may include couple of typos. Apologize if so. But it worked on very similar DB.
mDatabaseReference = mFirebaseDatabase.getReference();
ChildEventListener recentListener = new ChildEventListener() {
#Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if (dataSnapshot.getChildrenCount() > 0) {
for (DataSnapshot ds1 : dataSnapshot.getChildren()) {
ExecutiveOrder executiveOrder = ds1.getValue(ExecutiveOrder.class);
String title = executiveOrder.getTitle();
Log.i("MainActivity", "Title: " + title);
}
}
}
#Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
#Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
}
};
mDatabaseReference.addChildEventListener(recentListener);
There is a mismatch between variable names of the class and the corresponding database entries. The key in the database has the name "title" whereas you declare it as "mTitle" in your ExecutiveOrder.java class. Therefore, you are getting 'null'. Change the variable names in your ExecutiveOrder.java to match the "key" names exactly in the database and it should work fine.
All the best!!
Related
Ok so I've been looking for related articles regarding this, I've made a few experiments but I can't understand why I can't still get the values of note, date_time and vaccine objects... I'm planning on putting them in a ListView and I already got the key from the list of data using ChildEventListener
lastlastref = myRef.child(babyid).child("baby_features").child("immunization_records");
lastlastref.addChildEventListener(new ChildEventListener() {
#Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
String string = dataSnapshot.getValue(String.class);
}
#Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
#Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
and then I've tried using EventListener to get the values inside of it
lastlastref = myRef.child(babyid).child("baby_features").child("immunization_records");
lastlastref.addChildEventListener(new ChildEventListener() {
#Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
String string = dataSnapshot.getValue(String.class);
DatabaseReference newRef = lastlastref.child(string);
newRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot snapshot) {
note = snapshot.child("note").getValue(String.class);
vaccine = snapshot.child("vaccine").getValue(String.class);
timestamp = snapshot.child("date_time").getValue(String.class);
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
arrayList.add(vaccine + "" + timestamp + "" + note);
adapter.notifyDataSetChanged();
}
#Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
#Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
But the app still crashes and logcat says "Can't pass null for argument 'pathString' in child()"
You set up your reference to:
lastlastref = myRef.child(babyid).child("baby_features").child("immunization_records");
So each child node under this location is a JSON object like this:
{
"date_time": "November/16/2018...",
"note": "hhjj...",
"vaccine": "Measles"
}
But in your onChildAdded, you're trying to retrieve a single string value. Since the above JSON object is not a single string value, the getValue(String.class) returns null.
To get the values, you can call getValue() on the individual properties:
lastlastref.addChildEventListener(new ChildEventListener() {
#Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
String date_time = dataSnapshot.child("date_time").getValue(String.class);
String note = dataSnapshot.child("note").getValue(String.class);
String vaccine = dataSnapshot.child("vaccine").getValue(String.class);
}
You can also create a minimal class to wrap each record, and read that. The simplest version of that is:
public class ImmunizationRecord {
public String date_time;
public String note;
public String vaccine;
}
And the reading would then be done with:
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
String record = dataSnapshot.getValue(ImmunizationRecord.class);
}
A small side note about the way you store date_time. This format will lead to problems as you progress, since it is not sortable. If you need to store time stamps, store them as milliseconds since the epoch, or in a string format that allows them to be sorted (e.g. 2018-11-16T11:29:00).
I have been struggling with this issue for about three days. Or may be I am not understanding the who concept of addValueEventListener(). I have a POJO class.
public class InstantMessage {
private String UID;
private String email;
private String password;
private String type;
public InstantMessage() {
}
public InstantMessage(String newUID, String newEmail, String newPassword, String newType) {
UID = newUID;
email = newEmail;
password = newPassword;
type = newType;
}
public void setUID(String newUID) {
UID = UID;
}
public void setEmail(String newEmail) {
email = newEmail;
}
public void setPassword(String newPassword) {
password = newPassword;
}
public void setType(String newType) {
type = newType;
}
public String getUID() {
return UID;
}
public String getEmail()
{
return email;
}
public String getPassword()
{
return password;
}
public String getType()
{
return type;
}
}
What I am actually trying to achieve is to fetch "type" node from Firebase database. My database reference is:
mDatabaseReference = FirebaseDatabase.getInstance().getReference().child("Users");
I have tried to loop through the Datasnapshot object still no luck.
Here's what I am trying to do.
private void showData(){
mDatabaseReference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
InstantMessage iM1 = dataSnapshot.getValue(InstantMessage.class);
//System.out.println("The type is:" + iM1.getType());
sampleUser.add(iM1);
studentAdapter.notifyDataSetChanged();
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
As you can see in the logs that Datasnapshot is getting an object I am looking for but values are null.
I am so sorry if it's just a novice question but I am trying hard to learn it. Any help would be greatly appreciated.
You're getting a list of all users (from /Users), and then try to map the entire result to a single InstantMessage. That won't work, since the properties in InstantMessage don't exist straight in /Users, they are one level deeper in your JSON.
To solve this problem, you'll need to loop over the child nodes of your snapshot to get at the individual messages:
mDatabaseReference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot messageSnapshot: dataSnapshot.getChildren()) {
InstantMessage iM1 = messageSnapshot.getValue(InstantMessage.class);
sampleUser.add(iM1);
}
studentAdapter.notifyDataSetChanged();
}
#Override
public void onCancelled(DatabaseError databaseError) {
throw databaseError.toException(); // don't ignore errors
}
});
I am implementing Firebase and DataSnapshot return null to custom java object. I have try to solved this issue by following some answer using this site also but I don't know where is exact issue in my code.
Here I am attaching my screenshot of firebase database so kindly help me resolve this issue
Below is my model.
public class ChatModel {
private String messege;
private String user;
private int intType;
public ChatModel(){}
public ChatModel(String messege, String user, int intType) {
this.messege = messege;
this.user = user;
this.intType = intType;
}
public String getMessege() {
return messege;
}
public void setMessege(String messege) {
this.messege = messege;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public int getIntType() {
return intType;
}
public void setIntType(int intType) {
this.intType = intType;
}
}
and here is my activitycode.
DatabaseReference messagesReference = reference1.child("messages/"+ UserDetails.username + "_" + UserDetails.chatWith);
Log.e("messages URL "," ==>"+messagesReference);
messagesReference .addChildEventListener(new ChildEventListener() {
#Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Log.e("messages Referencev "," ==>"+dataSnapshot.toString());
ChatModel map = dataSnapshot.getValue(ChatModel.class);
String message = map.getMessege();
String userName = map.getUser();
Log.e("message "," ==>"+message); // Here I am getting null value
}
#Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
#Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
and logcat show message like this.
==>DataSnapshot { key = -KslrqBPRMNKkWQO15h_, value = {message=Hi This is sakib, user=sakib} }
Your keys are mismatch that's why it's returning null value check your screenshot and your ChatModel class, remove str from your ChatModel class variables, and generate getter setter again
This might help you.
public class ChatModel {
private String messege;
private String user;
private int intType;
// TODO generate getter setter again
}
either you can get values via map as well
Map<String,String> map=(Map<String,String>)dataSnapshot.getValue();
String message = map.get("message");
String userName = map.get("user");
Log.e("message "," ==>"+message);
Try to rename your model
private String message;
public String getMessage(){ return message;}
i had the same issue and it worked after i named the properties exactly like they are named in the firebase Database.
You can try to use dataSnapshot.getChildren() in the for loop, like this:
#Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if (dataSnapshot.exists()) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
ChatModel map = snapshot.getValue(ChatModel.class);
String message = map.getMessege();
String userName = map.getUser();
}
}
Hi i am using DatabaseReference#push method to add object to reference.
This object has property id.
Next time i have id and i wish to get that user object from that list, how can i get that. I there any simple way to directly Query, or we need to pull all objects and compare each id with the one i require,
here is my object code
#IgnoreExtraProperties
public final class User {
private Integer id;
private String name;
private String secret;
public User() {
}
public User(Integer id, String name, String secret) {
this.id = id;
this.name = name;
this.secret = secret;
}
public Integer getId() {
return id;
}
public String getName() {
return name;
}
public String getSecret() {
return secret;
}
public void setId(Integer id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setSecret(String secret) {
this.secret = secret;
}
}
This is how i am adding it to firebase console mReference.push().setValue(user); , also i want to know that can we omit thos random generated id for node, becuase i will not be having that kp*** id instead i will be havind id of user object
Her is how i am try to query more code :)
public final class UserReference implements ChildEventListener {
private static final String TAG = UserReference.class.getSimpleName();
private static final List<User> userList = new ArrayList<>();
static {
userList.add(new User(1, "user1", "secret1"));
userList.add(new User(2, "user2", "secret2"));
}
private static final String USER = "users";
private final DatabaseReference mReference;
private Query mSingleUserQuery;
UserReference(FirebaseDatabase database) {
mReference = database.getReference(USER);
// mReference.addChildEventListener(this);
}
//One time use method
public void saveUser() {
for (User user : userList) {
mReference.push().setValue(user);
}
}
public void findUserById(final String id, final OnDbCompleteListener<User> userListener) {
mSingleUserQuery = mReference.orderByChild("id").equalTo(id);
mSingleUserQuery.addChildEventListener(new ChildEventListener() {
#Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Logger.info(TAG, "Key: " + dataSnapshot.getValue());
sendDataAndUnregister(dataSnapshot);
}
#Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
Logger.info(TAG, dataSnapshot.getKey());
sendDataAndUnregister(dataSnapshot);
}
#Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
Logger.info(TAG, dataSnapshot.getKey());
sendDataAndUnregister(dataSnapshot);
}
#Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
Logger.info(TAG, dataSnapshot.getKey());
sendDataAndUnregister(dataSnapshot);
}
#Override
public void onCancelled(DatabaseError databaseError) {
databaseError.toException().printStackTrace();
}
private void sendDataAndUnregister(DataSnapshot dataSnapshot) {
mSingleUserQuery.removeEventListener(this);
userListener.onComplete(dataSnapshot.getValue(User.class));
}
});
}
#Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Logger.info(TAG, "added: " + dataSnapshot.getKey());
}
#Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
Logger.info(TAG, "changed: " + dataSnapshot.getKey());
}
#Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
Logger.info(TAG, "removed: " + dataSnapshot.getKey());
}
#Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
Logger.info(TAG, "moved: " + dataSnapshot.getKey());
}
#Override
public void onCancelled(DatabaseError databaseError) {
Logger.info(TAG, "Error: " + databaseError.getMessage());
}
}
Database Class
public final class MySuperCoolDatabase {
private FirebaseDatabase mDatabase;
private UserReference mUserReference;
public MySuperCoolDatabase() {
mDatabase = FirebaseDatabase.getInstance();
mUserReference = new UserReference(mDatabase);
}
public UserReference getUserReference() {
return this.mUserReference;
}
}
Its call:
MySuperCoolDatabase database = new MySuperCoolDatabase();
UserReference userReference = database.getUserReference();
userReference.findUserById("1", new OnDbCompleteListener<User>() {
#Override
public void onComplete(User user) {
Logger.info(TAG, "YAYA");
}
});
DbUpdateListener:
public interface OnDbCompleteListener<T> {
void onComplete(T t);
}
Thanks to #FrankvanPuffelen i had to do following changes, because i was storing id as Integer so i should request for Integer only.
public void findUserById(final Integer id, final OnDbCompleteListener<User> userListener) {
mSingleUserQuery = mReference.orderByChild("id").equalTo(id);
...
}
From
public void findUserById(final String id, final OnDbCompleteListener<User> userListener) {
mSingleUserQuery = mReference.orderByChild("id").equalTo(id);
...
}
Also along with this changes i had to add index as suggested in console by firebase war logger here is the rules files
{
"rules": {
".read": true,
".write": false,
"users": {
".indexOn": "id"
}
}
}
For pushing value directly into node, you could use -
User user = "detail of your user";
// On firebase reference push value on id directly.
ref.child("1").setValue("user);
Here "1" is an id which is going to be primary key for your user detail.
Update -
public void saveUser() {
for (User user : userList) {
mReference.child(user.id).setValue(user);
}
}
I'm trying to get the data from Firebase child node. But it throws Can't convert object of type java.lang.String to type uk.co.stableweb.geethika.model.DailyVerse exception.
This is the structure of my Firebase database.
Here is the code. I'm using Android Firebase new documentation.
mRef = FirebaseDatabase.getInstance().getReference().child("daily_verse");
mRef.keepSynced(true);
ChildEventListener childEventListener = new ChildEventListener() {
#Override
public void onChildAdded(DataSnapshot dataSnapshot, String previousChildName) {
Log.d("Child Event,Verse", dataSnapshot.getKey());
dailyVerse = dataSnapshot.getValue(DailyVerse.class);
}
#Override
public void onChildChanged(DataSnapshot dataSnapshot, String previousChildName) {
Log.d("Child Event,Verse", "onChildChanged:" + dataSnapshot.getKey());
dailyVerse = dataSnapshot.getValue(DailyVerse.class);
}
#Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
#Override
public void onChildMoved(DataSnapshot dataSnapshot, String previousChildName) {
}
#Override
public void onCancelled(DatabaseError databaseError) {
Log.w("Firebase", "onCancelled", databaseError.toException());
Toast.makeText(context, "Failed to load verse",
Toast.LENGTH_SHORT).show();
}
};
mRef.addChildEventListener(childEventListener);
And Model class.
public class DailyVerse {
private String verse_title;
private String verse_content;
public String getVerseTitle() {
return verse_title;
}
public void setVerseTitle(String verse_title) {
this.verse_title = verse_title;
}
public String getVerseContent() {
return verse_content;
}
public void setVerseContent(String verse_content) {
this.verse_content = verse_content;
}
}
And the LogCat.
com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.String to type uk.co.stableweb.geethika.model.DailyVerse
at com.google.android.gms.internal.zzalq.zzd(Unknown Source)
at com.google.android.gms.internal.zzalq.zzb(Unknown Source)
at com.google.android.gms.internal.zzalq.zza(Unknown Source)
at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
at uk.co.stableweb.geethika.VerseActivityFragment$1.onChildAdded(VerseActivityFragment.java:63)
at com.google.android.gms.internal.zzahh.zza(Unknown Source)
at com.google.android.gms.internal.zzajh.zzctc(Unknown Source)
at com.google.android.gms.internal.zzajk$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
But if I change the database reference as follows. And get the dataSnapshot value, it grabs the data.
mRef = FirebaseDatabase.getInstance().getReference("daily_verse");
testVal = (String) dataSnapshot.getValue();
Log.d("TEST", testVal);
V/FA: Activity resumed, time: 278033062
D/Child Event,Verse added: verse_content
D/TEST: විශ්වාසකමේ මාර්ගය තෝරා ගතිමි. ඔබගේ විනිශ්චයන් මා ඉදිරියෙහි තබා ගතිමි.
D/Child Event,Verse added: verse_title
D/TEST: ගීතාවලිය 119:30
I think it is possible to get those values using HashMap. But there was a comment saying it is no longer recommended.
Pay careful attention to the names of your properties in the JSON and your fields/getters in the Java code. If they don't match, the Firebase client won't be able to match the values between them.
Your JSON has verse_title and verse_content, so your Java class must be either:
public class DailyVerse {
public String verse_title;
public String verse_content;
}
or:
public class DailyVerse {
private String verse_title;
private String verse_content;
public String getVerse_title() {
return verse_title;
}
public void setVerse_title(String verse_title) {
this.verse_title = verse_title;
}
public String getVerse_content() {
return verse_content;
}
public void setVerse_content(String verse_content) {
this.verse_content = verse_content;
}
}
Since Firebase Android SDK 9.2, you can also annotate your Java code to map to the correct JSON properties. So a third way to get the correct mapping is:
public class DailyVerse {
private String verse_title;
private String verse_content;
#PropertyName("verse_title")
public String getVerseTitle() {
return verse_title;
}
public void setVerseTitle(String verse_title) {
this.verse_title = verse_title;
}
#PropertyName("verse_content")
public String getVerseContent() {
return verse_content;
}
public void setVerseContent(String verse_content) {
this.verse_content = verse_content;
}
}
I haven't tried that latest variant though, so let me know if there are typos on the answer.
By this method
mRef.addChildEventListener(childEventListener);
you subscribe for
.child("daily_verse");
children. daily_verse has two children: verse_content and verse_title. The type of these children is String. So, you get two String datasnapshot in the onChildAdd listener.
Update:
Try something like this:
mRef = FirebaseDatabase.getInstance().getReference();
mRef.keepSynced(true);
ChildEventListener childEventListener = new ChildEventListener() {
#Override
public void onChildAdded(DataSnapshot dataSnapshot, String previousChildName) {
Log.d("Child Event,Verse", dataSnapshot.getKey());
if ("daily_verse".equal(dataSnapshot().getKey){
dailyVerse = dataSnapshot.getValue(DailyVerse.class);
Log.d("TEST","Object: "+dailyVerse);
if (dailyVerse!=null){
Log.d("TEST","values: "+dailyVerse.verse_title+", "+dailyVerse.verse_content);
}
}
}
#Override
public void onChildChanged(DataSnapshot dataSnapshot, String previousChildName) {
Log.d("Child Event,Verse", "onChildChanged:" + dataSnapshot.getKey());
if ("daily_verse".equal(dataSnapshot().getKey){
dailyVerse = dataSnapshot.getValue(DailyVerse.class);
Log.d("TEST","Changed object: "+dailyVerse);
if (dailyVerse!=null){
Log.d("TEST","Changed values: "+dailyVerse.verse_title+", "+dailyVerse.verse_content);
}
}
}
#Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
#Override
public void onChildMoved(DataSnapshot dataSnapshot, String previousChildName) {
}
#Override
public void onCancelled(DatabaseError databaseError) {
Log.w("Firebase", "onCancelled", databaseError.toException());
Toast.makeText(context, "Failed to load verse",
Toast.LENGTH_SHORT).show();
}
};
mRef.addChildEventListener(childEventListener);
You should subscribe to events from parent object and check the key at events listener.
DataRef = FirebaseDatabase.getInstance().getReference().child("Users");
DataRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
String acctname = (String)dataSnapshot.child("Name").getValue();
String acctmail = (String)dataSnapshot.child("Email").getValue();
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
When using a firebase model class, You have to include an empty constructor for firebase to work with.
Try adding it as
public class DailyVerse {
public DailyVerse(){
}
}
ArrayList<EventsResponse> usersEventsList = new ArrayList<>();
dummyIdsArrayList = new ArrayList<>();
Iterator<DataSnapshot> eventsIterator = dataSnapshot.getChildren().iterator();
while (eventsIterator.hasNext()) {
DataSnapshot eventsSnapShot = eventsIterator.next();
EventsResponse eventsResponse = new EventsResponse();
eventsResponse.setEventName(eventsSnapShot.getKey());
Iterator<DataSnapshot> eventChildIterator = eventsSnapShot.getChildren().iterator();
while (eventChildIterator.hasNext()) {
DataSnapshot eventchildSnapshot = eventChildIterator.next();
if (eventchildSnapshot.getKey().equals("is_recursive")) {
eventsResponse.setRecursive((Boolean) eventchildSnapshot.getValue());
} else if (eventchildSnapshot.getKey().equals("is_notif")) {
eventsResponse.setNotif((Boolean) eventchildSnapshot.getValue());
} else if (eventchildSnapshot.getKey().equals("is_editable")) {
eventsResponse.setEditable((Boolean) eventchildSnapshot.getValue());
} else if (eventchildSnapshot.getKey().equals("is_visible")) {
eventsResponse.setVisible((Boolean) eventchildSnapshot.getValue());
} else if (eventchildSnapshot.getKey().equals("name")) {
eventsResponse.setName(eventchildSnapshot.getValue().toString());
} else if (eventchildSnapshot.getKey().equals("date")) {
Iterator<DataSnapshot> eventChildDateIterator = eventchildSnapshot.getChildren().iterator();
while (eventChildDateIterator.hasNext()) {
DataSnapshot eventchildDateSnapshot = eventChildDateIterator.next();
if (eventchildDateSnapshot.getKey().equals("day")) {
eventsResponse.setDay(eventchildDateSnapshot.getValue().toString());
} else if (eventchildDateSnapshot.getKey().equals("month")) {
eventsResponse.setMonth(eventchildDateSnapshot.getValue().toString());
} else if (eventchildDateSnapshot.getKey().equals("year")) {
eventsResponse.setYear(eventchildDateSnapshot.getValue().toString());
}
}
} else {
eventsResponse.setNotif(true);
eventsResponse.setVisible(false);
}
}
if you are not able to fetch data,then you can fetch the data in that format.