Getting 'attempt To Invoke Virtual Method 'java.lang.string Java.lang.string.trim()' On A Null Object Reference' Even When The Reference Is Not Null
I'm using FirebaseUI in my app and FirebaseRecyclerAdapter to be more specific. I'm fetching data from my FirebaseDatabase reference using the method given here. Here's my code: pr
Solution 1:
If this causes the error:
Map<String, String> map = (Map<String, String>) dataSnapshot.getValue();
String cLatS = map.get("cLat").trim();
The reason is most likely, that dataSnapshot
has no child cLat
.
You should check with .hasChild("cLat")
- see DataSnapshot
... or prevent the attempted .trim(null)
alike:
if(map.get("cLat") != null) {
String cLatS = map.get("cLat").trim();
currentLtAU = Double.parseDouble(cLatS);
}
While for this kind of application, you might want to check out Firebase GeoFire.
Post a Comment for "Getting 'attempt To Invoke Virtual Method 'java.lang.string Java.lang.string.trim()' On A Null Object Reference' Even When The Reference Is Not Null"