从Firebase数据库的菜单列表加载食物列表时,我在logcat中收到此错误。 这是文件,请帮我。我正在android nougat apk 24中运行该应用程序。
public class FoodList extends AppCompatActivity {
RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;
FirebaseDatabase database;
DatabaseReference foodList;
String categoryId;
FirebaseRecyclerAdapter<Food,FoodViewHolder> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_food_list);
database=FirebaseDatabase.getInstance();
foodList=database.getReference("Food");
recyclerView=(RecyclerView)findViewById(R.id.recycler_food);
recyclerView.setHasFixedSize(true);
layoutManager=new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
if(getIntent()!=null) {
categoryId = getIntent().getStringExtra("CategoryId");
if(categoryId != null&& !categoryId.isEmpty()) {
loadListFood(categoryId);
}
}
}
private void loadListFood(String categoryId) {
adapter=new FirebaseRecyclerAdapter<Food, FoodViewHolder>(Food.class,
R.layout.food_item,FoodViewHolder.class,
foodList.orderByChild("MenuId").equalTo(categoryId)) {
@Override
protected void populateViewHolder(FoodViewHolder viewHolder, Food model, int position) {
viewHolder.food_name.setText(model.getName());
Picasso.with(getBaseContext()).load(model.getImage()).into(viewHolder.food_image);
final Food local=model;
viewHolder.setItemClickListener(new ItemClickListener() {
@Override
public void onclick(View view, int position, boolean isLongClick) {
Toast.makeText(FoodList.this, ""+local.getName(), Toast.LENGTH_SHORT).show();
}
});
}
};
recyclerView.setAdapter(adapter);
}
}