我有一个非常奇怪的问题。此代码几天前仍在工作,但现在它正在使我的应用程序崩溃。我正在尝试循环访问节点子节点。
private void getInfo()
{
FirebaseDatabase.getInstance().getReference()
.child("ForumResponses").child(forumID).addListenerForSingleValueEvent(new ValueEventListener()
{
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
{
for(DataSnapshot snap : dataSnapshot.getChildren())
{
ForumResponses forumResponses = snap.getValue(ForumResponses.class);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
{
}
});
}
如果我删除下面的代码行,应用程序不会崩溃。这是为什么呢?
ForumResponses forumResponses = snap.getValue(ForumResponses.class);
下面是错误日志
com.google.firebase.database.DatabaseException: Failed to convert a value of type java.util.HashMap to int
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertInteger(com.google.firebase:firebase-database@@16.1.0:351)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToPrimitive(com.google.firebase:firebase-database@@16.1.0:272)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-database@@16.1.0:197)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToType(com.google.firebase:firebase-database@@16.1.0:178)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.access$100(com.google.firebase:firebase-database@@16.1.0:47)
ITMISS
相关分类