gpt4 book ai didi

java - 我正在从 Firebase 拍摄数据,但无法将其添加到列表中

转载 作者:行者123 更新时间:2023-12-02 10:38:04 25 4
gpt4 key购买 nike

我实际上获取了数据并用 print 打印了它。但是当我添加到列表中时,它给出了空对象异常。我该如何解决这个问题?我收到错误,因为我正在创建一个空对象。我不明白为什么。,我该怎么做才能解决?

    myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren()){
Mac mac = new Mac();
mac.setMackodu(ds.getValue(Mac.class).getMackodu());
mac.setTakimlar(ds.getValue(Mac.class).getTakimlar());
mac.setTahmin(ds.getValue(Mac.class).getTahmin());
System.out.println("macss " + mac.getMackodu());
System.out.println("macss " + mac.getTakimlar());
System.out.println("macss " + mac.getTahmin());
macList.add(mac);

}

myRecyclerAdapter = new MyRecyclerAdapter(getContext(),macList);
recyclerView.setAdapter(myRecyclerAdapter);
myRecyclerAdapter.notifyDataSetChanged();

}
public class Mac{

private String macKodu;
private String takimlar;
private String tahmin;

public Mac() {
}

public Mac(String macKodu, String takimlar, String tahmin) {
this.macKodu = macKodu;
this.takimlar = takimlar;
this.tahmin = tahmin;
}

public String getMacKodu() {
return macKodu;
}

public void setMacKodu(String macKodu) {
this.macKodu = macKodu;
}

public String getTakimlar() {
return takimlar;
}

public void setTakimlar(String takimlar) {
this.takimlar = takimlar;
}

public String getTahmin() {
return tahmin;
}

public void setTahmin(String tahmin) {
this.tahmin = tahmin;
}

最佳答案

放入这两行

myRecyclerAdapter = new MyRecyclerAdapter(getContext(),macList);
recyclerView.setAdapter(myRecyclerAdapter);

myRef.addValueEventListener

关于java - 我正在从 Firebase 拍摄数据,但无法将其添加到列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53132346/

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