com.google.firebase.database.DatabaseException:找到名称冲突的getter:isChangingConfigurations

时间:2017-08-04 23:40:14

标签: android firebase

我正在尝试从firebase数据库中读取数据。当我运行它时我的应用程序崩溃,我似乎得到这个isChangingConfigurations错误。请注意,此Info类是片段,我不想使用listview读取数据库。我该如何解决这个问题?

Reading data from here

public class Info extends Fragment {

    private DatabaseReference mDatabase;
    private FirebaseAuth firebaseAuth;
    String userID;

    private TextView resNameChange, statusChange;

    public Info() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        View rootView = inflater.inflate(R.layout.fragment_info, container, false);

        mDatabase = FirebaseDatabase.getInstance().getReference();

        firebaseAuth = FirebaseAuth.getInstance();
        FirebaseUser user = firebaseAuth.getCurrentUser();
        userID = user.getUid();

        resNameChange = rootView.findViewById(R.id.resNameChange);
        statusChange = rootView.findViewById(R.id.statusChange);

        mDatabase.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                showData(dataSnapshot);
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
        return rootView;
    }

    public void showData(DataSnapshot dataSnapshot) {
        for (DataSnapshot ds : dataSnapshot.getChildren()) {
            RestaurantInformation resInfo = new RestaurantInformation();
            resInfo.setResName(ds.child(userID).getValue(RestaurantInformation.class).getResName()); // error in this line ************
            resInfo.setStatus(ds.child(userID).getValue(RestaurantInformation.class).getStatus());

            resNameChange.setText(resInfo.getResName());
            statusChange.setText(resInfo.getStatus());
        }
    }
}

RestaurantInformation类

public class RestaurantInformation extends AppCompatActivity {

    private String resName;
    private String status;

    public RestaurantInformation() {

    }

        public RestaurantInformation(String resName, String status) {
        this.resName = resName;
        this.status = status;
    }

    public String getResName() {
        return resName;
    }

    public void setResName(String resName) {
        this.resName = resName;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }
}

3 个答案:

答案 0 :(得分:1)

从错误消息中:isChangingConfigurationsActivity方法的名称。 Firebase无法序列化Activity对象。你应该删除这部分:

 extends AppCompatActivity

并且不要忘记删除导入import android.support.v7.app.AppCompatActivity;

答案 1 :(得分:0)

我遇到了同样的问题 我有一个在Acivity中声明的类,所以我将该类的声明从acivity更改为包级别,并且错误消失了

答案 2 :(得分:0)

去掉AppCompatActivity,部分代码将不起作用,例如, findViewById。