我正在尝试从Firebase Realtime数据库中获取数据并在回收器视图中显示该数据,但它显示了一个错误
recyclerView = findViewById(R.id.RecyclerView);
recyclerView.setHasFixedSize(true);
databaseReference = firebaseDatabase.getInstance().getReference().child("Collection");
options = new FirebaseRecyclerOptions.Builder<CategoryItem>().setQuery(databaseReference,CategoryItem.class).build();
adapter = new FirebaseRecyclerAdapter<CategoryItem, CtegoryViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull CtegoryViewHolder holder, int position, @NonNull CategoryItem model) {
Picasso.get().load(model.getImageLink()).into(holder.i1, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError(Exception e) {
Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
holder.t1.setText(model.getName());
}
@NonNull
@Override
public CtegoryViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.card_view_layout,viewGroup,false);
return new CtegoryViewHolder(view);
}
};
androidx.recyclerview.widget.GridLayoutManager gridLayoutManager = new GridLayoutManager(this,1);
recyclerView.setLayoutManager(gridLayoutManager);
adapter.startListening();
recyclerView.setAdapter(adapter);