com.google.firebase.database.DatabaseException:无法将java.lang.Boolean类型的对象转换为com.example.simpleapplocker.Users

时间:2019-09-08 20:29:06

标签: android firebase firebase-realtime-database

firbase data image

我想获取Firebase日期以回收视图,所以我将userSnapshot的值转换为Users.class,它显示错误,请帮助我,我看到错误“ com.google.firebase.database.DatabaseException:无法转换类型的对象java.lang.String键入com.example。***“ 但我有布尔错误

此处显示错误

DatabaseReference userref = FirebaseDatabase.getInstance().getReference().child("Connection").child("User");
        userref.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                if (dataSnapshot.exists()) {
                    for (DataSnapshot userSnapshot : dataSnapshot.getChildren()) {

                        Users users = userSnapshot.getValue(Users.class);
                        usersList.add(users);

                    }
                    mAdapter = new Adapter_All_Users(usersList);
                    mRecyclerView.setAdapter(mAdapter);


                }

            }
}

用户类只是一个简单的类

package com.example.simpleapplocker;

public class Users {
    private String Name;
    private String Email;
    private String Location;
    private String Age;
    private String Sex;

    public Users() {


    }

    public Users(String Name, String Email, String Location, String Age, String Sex) {
        this.Name = Name;
        this.Email = Email;
        this.Location = Location;
        this.Age = Age;
        this.Sex = Sex;
    }

    public String getName() {
        return Name;
    }

    public String getEmail() {
        return Email;
    }

    public String getLocation() {
        return Location;
    }

    public String getAge() {
        return Age;
    }

    public String getSex() {
        return Sex;
    }
}

不知道是什么问题

0 个答案:

没有答案