无法从firebase表中获取最后一条记录

时间:2016-12-29 18:50:49

标签: android firebase

我无法使用以下查询从聊天表中检索数据,有人可以看看。感谢

聊天表格式

chat
 GWyC4hqk9oRB3UxXbCV8IdqDT8M2-YazXdhCCTeF7KRQNKq2duS9qF3
 -K_89zEV7TLoeatnAToj
 action:""
 imagePath:""
 sender:"YazXdhCCTeF7KRQNKq2duS9qF3"
 text:"Hi"

 -K_8EmH2cB53KoW5qoX9
 action: ""
 imagePath: ""
 sender: "YazXdhCCTeF7KRQNKq2duS9qF3"
 text: "hi"

查询代码

 mRef = new Firebase("https://moe-90cc7.firebaseio.com/chat");
        Query limitQuery = mRef.child(chatRoom).limitToLast(1);
        limitQuery.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                final Message message = dataSnapshot.getValue(Message.class);
                 textView.setText(message.getText());

            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {

            }
        });

错误

Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "-K_8LQn9qhg2T-dmMmBD" (class app.chat.Message), not marked as ignorable (4 known properties: , "imagePath", "sender", "text", "action"])
                                                                  at [Source: java.io.StringReader@250d953e; line: 1, column: 26] (through reference chain: app.core.chat.Message["-K_8LQn9qhg2T-dmMmBD"])

1 个答案:

答案 0 :(得分:2)

您收到的数据似乎与Message班级成员不匹配。例外情况告诉您,-K_8LQn9qhg2T-dmMmBD类中应该有一个名为Message的成员,而它似乎是成员的值。

尝试在调试模式下显示dataSnapshot的内容,以便更好地了解问题。