我是新的Devoloper,我想使用Picasso从FirebaseDatabase加载图像。但是我得到这个错误;
抽象方法“ void com.squareup.picasso.Callback.onError(java.lang.Exception)
我不明白这是什么意思。因为我已经在使用Callback方法。这是我的适配器;
private void myAdapter() {
Query query = FirebaseDatabase.getInstance()
.getReference().child("Category");
FirebaseRecyclerOptions<Category> options = new FirebaseRecyclerOptions.Builder<Category>().setQuery(query, Category.class).build();
adapter = new FirebaseRecyclerAdapter<Category, MenuViewHolder>(options) {
@NonNull
@Override
public MenuViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.menu_item, parent, false);
return new MenuViewHolder(view);
}
@Override
protected void onBindViewHolder(@NonNull MenuViewHolder viewHolder, int position, @NonNull Category model) {
viewHolder.txtMenuName.setText(model.getName());
Picasso p = Picasso.get();
p.load(model.image).tag(this).into(viewHolder.menu_image, new Callback() {
@Override
public void onSuccess() {
Toast.makeText(Home.this, "Welcome", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(Exception e) {
Toast.makeText(Home.this, "Failed", Toast.LENGTH_SHORT).show();
e.getMessage();
}
});
final Category clickItem = model;
viewHolder.setItemClickListener(new ItemClickListener() {
@Override
public void onClick(View view, int position, boolean isLongClick) {
Toast.makeText(Home.this, "" + clickItem.getName(), Toast.LENGTH_SHORT).show();
Intent food_intent = new Intent(Home.this, FoodList.class);
//Because categoryId is key , so we just get key of this item
food_intent.putExtra(getCategoryId, adapter.getRef(position).getKey());
food_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(food_intent);
}
});
}
};
adapter.startListening();
}
我从互联网上搜索过Google,但找不到任何有用的信息。请帮助我,谢谢:)
这是我的模型课;
public class Category {
private String name;
public String image;
public Category() {
}
public Category(String name, String image) {
this.name = name;
this.image = image;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setImage(String image) {
this.image = image;
}
}
答案 0 :(得分:0)
我希望这对您有用。
尝试这样
Picasso.with(this).load(model.image).resize(400,400).into(viewHolder.menu_image, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
// onError Load Default Image.
}
});
答案 1 :(得分:0)
您的回调工作正常,但无法加载图片。您能否告诉我们更多有关“ model.image”的信息。尝试用一个硬编码的URL替换它,您确定它可以正常工作。