gpt4 book ai didi

java - 如何调试这个运行时错误?

转载 作者:太空宇宙 更新时间:2023-11-04 10:48:59 25 4
gpt4 key购买 nike

这是一个部分java文件,其中包含loadMenu函数,当相应的intent打开时,应用程序会意外关闭。

private void loadMenu() {
FirebaseRecyclerAdapter<Category,MenuViewHolder> adapter = new FirebaseRecyclerAdapter<Category, MenuViewHolder> (Category.class,R.layout.item_menu,MenuViewHolder.class,category) {
@Override
protected void populateViewHolder(MenuViewHolder viewHolder, Category model, int position) {

viewHolder.txtMenuname.setText(model.getName());
Picasso.with(getBaseContext()).load(model.getImage())
.into(viewHolder.imageView);
final Category clickItem = model;
viewHolder.setItemClickListener(new ItemClickListener() {
@Override
public void OnClick(View view, int position, boolean isLongClick) {
Toast.makeText(navi.this,""+clickItem.getName(),Toast.LENGTH_SHORT).show();
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

}
});

}
};
recycle_menu.setAdapter(adapter);
}

这是我的 MenuviewHolder 类:我刚刚在 firebase 中创建了一个图像数据库并将其链接到我的应用程序,但它不显示图像只是背景。

public class MenuViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

public TextView txtMenuname;
public ImageView imageView;
private ItemClickListener itemClickListener;
public MenuViewHolder(View itemView) {
super(itemView);

txtMenuname = (TextView)itemView.findViewById(R.id.menu_name);
itemView = (ImageView)itemView.findViewById(R.id.menu_image);
itemView.setOnClickListener(this);
}

public void setItemClickListener(ItemClickListener itemClickListener){
this.itemClickListener = itemClickListener;
}

@Override
public void onClick(View view) {
itemClickListener.OnClick(view,getAdapterPosition(),false);

}

}

使用 firebaseUI 将图像和名称链接到应用程序的适配器代码

public class Category {

private String Name;
private String Image;

public Category(){
}
public Category(String name, String image){
Name = name;
Image = image;
}

public String getName() {
return Name;
}

public void setName(String name) {
Name = name;
}


public String getImage() {
return Image;
}

public void setImage(String image) {
Image = image;
}
}

最佳答案

private void loadMenu() {
FirebaseRecyclerAdapter<Category,MenuViewHolder>
adapter = new
FirebaseRecyclerAdapter <Category, MenuViewHolder>

(Category.class,R.layout.item_menu,
MenuViewHolder.class,category) {
@Override
protected void


populateViewHolder(MenuViewHolder viewHolder,

Category model, int position) {


viewHolder.txtMenuname.setText(model.getName());
If (model.getimage() != null){

Picasso.with(getapplicationcontext()).
load (model.getImage())
.into(viewHolder.imageView);}
else {//Toast here}
final Category clickItem = model;
viewHolder.setItemClickListener(new

ItemClickListener() {
@Override
public void OnClick(View view, int position,

boolean isLongClick) {


Toast.makeText(navi.this,""+clickItem.getName(),
Toast.LEN
GTH_SHORT).show();
}

@Override
public void onItemClick(AdapterView<?> parent,

View view, int position, long id) {

}
});

}
};
recycle_menu.setAdapter(adapter);
}

关于java - 如何调试这个运行时错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48044840/

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