FirebaseRecyclerAdapter's PopulateViewHolder() Getting Called Before A Key Having Certain Values Gets Fully Removed Thus Giving Nullpointerexception
I am using FirebaseUI's FirebaseRecyclerAdapter in my app to fetch some data from a FirebaseDatabase reference and show it in a RecyclerView. I'm completing this task successfully.
Solution 1:
Well, I think I figured out a way.
Just placed some conditions in the code.
Here's the updated code:
if (dataSnapshot.getValue() != null) {
if (dataSnapshot.hasChild("pName") && dataSnapshot.hasChild("pUrl") && dataSnapshot.hasChild("cLat") && dataSnapshot.hasChild("cLng")) {
Map<String, String> map = (Map<String, String>) dataSnapshot.getValue();
pA = map.get("pName");
uA = map.get("pUrl");
String cLatS = map.get("cLat").trim();
currentLtAU = Double.parseDouble(cLatS);
String cLngS = map.get("cLng").trim();
currentLnAU = Double.parseDouble(cLngS);
viewHolder.setPName(pA);
viewHolder.setPUrl(uA);
viewHolder.setCurrentLatAU(String.valueOf(currentLtAU));
viewHolder.setCurrentLngAU(String.valueOf(currentLnAU));
}
}
and now everything works perfectly fine!
Post a Comment for "FirebaseRecyclerAdapter's PopulateViewHolder() Getting Called Before A Key Having Certain Values Gets Fully Removed Thus Giving Nullpointerexception"