Search code examples
androidcallbackadapterpicassoonerror

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


I'm new Devoloper, I want to load image from FirebaseDatabase with Picasso. But I'm getting this error ;

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

I dont understand what it means. Because I'm using already Callback method. Here is my adapter ;

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

I have googled from internet but I couldn't find anything useful to do. Please help me and thank you :)

this is my model 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;
    }
}

this is my FirebaseDatabase constructor


Solution

  • Your callback is working fine, but the image couldn't be loaded. Could you tell us more about "model.image". Try replacing it with a hardcoded URL, you are sure of that it works.