gpt4 book ai didi

java - 从 firebase 数据库读取数据到自定义 listView

转载 作者:行者123 更新时间:2023-12-02 01:05:28 24 4
gpt4 key购买 nike

enter image description here我正在尝试读取插入到 firebase 数据库中的数据,我想在自定义 listView 中显示数据。我正在使用这种方法,但似乎我错过了一些东西。我无法将数据插入我的数组列表。更新我插入了值,现在它给了我

attempt to invoke a virtual method on a null object reference on my get methods

private void showData(DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
PatientInformation patientInfo = new PatientInformation();
patientInfo.setName(ds.child(userID).getValue(PatientInformation.class).getName());
patientInfo.setAge(ds.child(userID).getValue(PatientInformation.class).getAge());
patientInfo.setDate(ds.child(userID).getValue(PatientInformation.class).getDate());
ArrayList<PatientInformation> arrayList = new ArrayList<>();
arrayList.add(patientInfo);
PatientInformationAdapter pAdapter = new PatientInformationAdapter(this, arrayList);
listView.setAdapter(pAdapter);
}

最佳答案

您的 arrayList 是 PatientInformation 类型,因此我认为您可以添加也是 PatientInformation 类型的 PatientInfo。

private void showData(DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
PatientInformation patientInfo = new PatientInformation();
patientInfo.setName(ds.child(userID).getValue(PatientInformation.class).getName());
patientInfo.setAge(ds.child(userID).getValue(PatientInformation.class).getAge());
patientInfo.setDate(ds.child(userID).getValue(PatientInformation.class).getDate());
ArrayList<PatientInformation> arrayList = new ArrayList<>();
arrayList.add(patientInfo);

PatientInformationAdapter pAdapter = new PatientInformationAdapter(this, arrayList);
listView.setAdapter(pAdapter);
}

关于java - 从 firebase 数据库读取数据到自定义 listView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60102451/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com