抽象方法 "void com.squareup.picasso.Callback.onError(java.lang.Exception)



我是新Devoloper,我想用毕加索从FirebaseDatabase加载图像。但是我收到此错误;

抽象方法 "void com.squareup.picasso.Callback.onError(java.lang.Exception(

我不明白这是什么意思。因为我已经在使用回调方法。这是我的适配器;

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();
}

我从互联网上用谷歌搜索过,但我找不到任何有用的事情要做。请帮助我,谢谢你:)

这是我的模型课;

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;
}
}

这是我的Firebase数据库构造函数

您的回调工作正常,但无法加载图像。你能告诉我们更多关于"模型.图像"的信息吗?尝试将其替换为硬编码的URL,您确定它可以工作。

我希望这对你有用。

像这样尝试,

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.
}
});

相关内容

最新更新