gpt4 book ai didi

java - Firestore Recycler 未在应用屏幕上显示任何结果且没有错误

转载 作者:行者123 更新时间:2023-12-01 23:03:55 26 4
gpt4 key购买 nike

我想使用 Firebase 制作一个杂务应用程序,它有 2 个输入:描述和类。每当我运行该应用程序时,显示的屏幕都是空白的(标题除外)没有明确的指示或错误可能显示问题。这些是最富有成果的 logCat 日志区域:

2019-07-12 16:42:37.306 5300-5300/? W/Firestore: (20.1.0) [CustomClassMapper]: No setter/field for length found on class com.example.choretest.Chores
2019-07-12 16:42:37.306 5300-5300/? W/Firestore: (20.1.0) [CustomClassMapper]: No setter/field for description found on class com.example.choretest.Chores
2019-07-12 16:42:37.307 5300-5300/? W/Firestore: (20.1.0) [CustomClassMapper]: No setter/field for length found on class com.example.choretest.Chores
2019-07-12 16:42:37.307 5300-5300/? W/Firestore: (20.1.0) [CustomClassMapper]: No setter/field for description found on class com.example.choretest.Chores
2019-07-12 16:42:37.307 5300-5300/? W/Firestore: (20.1.0) [CustomClassMapper]: No setter/field for length found on class com.example.choretest.Chores
2019-07-12 16:42:37.308 5300-5300/? W/Firestore: (20.1.0) [CustomClassMapper]: No setter/field for description found on class com.example.choretest.Chores

2019-07-12 16:43:47.301 5300-5385/com.example.choretest V/FA: Inactivity, disconnecting from the service

由于我没有其他线索,我已尝试检查以确保所有集合和文档的名称都一致。

主要 Activity :

private RecyclerView mMainList;
private static final String TAG = "MainActivity";

public FirebaseFirestore mFirestore;

private ChoresListAdapter ChoresListAdapter;

private List<Chores> choreList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mMainList = (RecyclerView) findViewById(R.id.main_list);
mFirestore = FirebaseFirestore.getInstance();
choreList = new ArrayList<>();
ChoresListAdapter = new ChoresListAdapter(choreList);
mMainList.setHasFixedSize(true);
mMainList.setLayoutManager(new LinearLayoutManager(this));
mMainList.setAdapter((ChoresListAdapter));


mFirestore.collection("choreList").addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
if(e != null){
Log.d(TAG, "ERROR: " + e.getMessage());
}

for(DocumentChange doc : queryDocumentSnapshots.getDocumentChanges()){
if(doc.getType() == DocumentChange.Type.ADDED){
Chores chores = doc.getDocument().toObject(Chores.class);
choreList.add(chores);

ChoresListAdapter.notifyDataSetChanged();


}
}


}
});
}

中学杂务课:

String chore, time;

public Chores(){

}

public Chores(String chore, String time) {
this.chore = chore;
this.time = time;
}

public String getChore() {
return chore;
}

public void setChore(String chore) {
this.chore = chore;
}

public String getTime() {
return time;
}

public void setTime(String time) {
this.time = time;
}

回收器 View 的适配器:

public List<Chores> choreList;

public ChoresListAdapter(List<Chores> choreList){
this.choreList = choreList;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false);
return new ViewHolder(view);

}

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.lengthText.setText(choreList.get(position).getTime());
holder.descriptionText.setText(choreList.get(position).getChore());
}

@Override
public int getItemCount() {
return choreList.size();
}

public class ViewHolder extends RecyclerView.ViewHolder{
View mView;

public TextView descriptionText;
public TextView lengthText;


public ViewHolder(@NonNull View itemView) {
super(itemView);
mView = itemView;

descriptionText = (TextView) mView.findViewById(R.id.description_text);
lengthText = (TextView) mView.findViewById(R.id.length_text);
}
}

我希望输出是 firestore 集合上的消息列表,但实际上只有一个空白屏幕。

最佳答案

问题是 Chores 类中的字段名称与数据库中存在的名称不同。要解决此问题,您应该将模型类中的 choretime 属性名称更改为 descriptionlenght 或您应该更改数据库中的名称以匹配模型类中的名称。

另一种解决方法可能是使用注释。您可以将字段设置为公开,并在每个字段前面添加以下注释:

@PropertyName("description")
public String chore;
@PropertyName("lenght")
public String time

所以请记住,模型类中的所有字段名称都必须与数据库中存在的名称相匹配。

关于java - Firestore Recycler 未在应用屏幕上显示任何结果且没有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58410734/

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