问题
I'm trying to retrieve some data from Firebase
using addChildEventListener()
like this (code is in a Service
):
aReference.child(requestID).addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if (dataSnapshot.getValue() != null) {
// error on the line below
Map<String, String> nUser = (Map<String, String>) dataSnapshot.getValue();
userNameAU = nUser.get("uName");
Log.d("uName", userNameAU);
}
...
...
});
but I'm getting this runtime error: java.lang.ClassCastException: java.lang.Long cannot be cast to java.util.Map
.
As you can see, I'm not even trying to cast it any Long
here, then why am I getting this error? The same code works fine in another activity.
来源:https://stackoverflow.com/questions/41294540/getting-java-lang-classcastexception-java-lang-long-cannot-be-cast-to-java-uti