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

abstract method "void com.squareup.picasso.Callback.onError(java.lang.Exception)

我是 Devoloper 新手,我想使用 Picasso 从 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();
    }

我已经从互联网上搜索过,但找不到任何有用的东西。请帮助我,谢谢 :)

这是我的模型class;

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

这是我的 FirebaseDatabase constructor

我希望这对你有用。

这样试试,

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

您的回调工作正常,但无法加载图片。你能告诉我们更多关于 "model.image" 的信息吗?尝试用硬编码 URL 替换它,你确定它有效。