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

醉酒当歌 提交于 2019-12-12 01:54:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!