Getting 'java.lang.ClassCastException: java.lang.Long cannot be cast to java.util.Map' even when I'm not casting any Long

1.1k Views Asked by At

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.

0

There are 0 best solutions below