从firebase检索数据:FirebaseException:无法退回到键入

时间:2016-07-18 13:38:10

标签: android firebase firebase-realtime-database

JSON FIREBASE DATA: 这里添加了firebase数据库的数据

TextField

模型类 此类仅适用于登录凭据

 {
  "login" : {
    "9847002233" : {
      "name" : "Saj",
      "number" : "9847002233",
      "password" : "123456"
    },
   "9847123123" : {
     "name" : "jishnu",
     "number" : "9847123123",
     "password" : "123456"
   }
  }
}

CODE FOR READ: 我试图检索数据,因为返回类型完全不同,发生时间错误,我期望与LoginData类型相同,返回另一个HashMap

public class LoginData {
String number;
String password;
String name;

public LoginData(String name , String number, String password) {
    this.number = number;
    this.password = password;
    this.name = name;
}

public String getNumber() {
    return number;
}

public void setNumber(String number) {
    this.number = number;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}
}

错误日志

           firebaseReference.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                GenericTypeIndicator<Map<String,LoginData>> mapType = new GenericTypeIndicator<Map<String, LoginData>>() { };
                Map<String,LoginData> logindatalist = dataSnapshot.getValue(mapType);
                if (logindatalist!=null) {
                    for (LoginData data: logindatalist.values()) {
                        System.out.println(data.getName());
                    }
                }
            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {

            }
        });

1 个答案:

答案 0 :(得分:0)

您在模型类中缺少默认构造函数(不带参数)。

public LoginData() {}