S
S
SimpleName2019-04-14 22:03:30
Java
SimpleName, 2019-04-14 22:03:30

Unable to get methods from interface in fragment. How can this be fixed?

Why, when trying to get methods from the interface, writes Cannot resolve method 'isProduct()'and Cannot resolve method 'getMenuTitle()'.
ourMenuItemsI write likeArrayList

private final ArrayList<MenuPosition> ourMenuItems = new ArrayList<>();

Everything is there in the interface, but in the fragment it is still impossible to get them. How can this be fixed?
Here is the MenuPosition interface code

public interface MenuPosition {
public String getIcon();
public int getId();
public String getImageUrl();
public String getMenuTitle();
public boolean isProduct();
}
Screen
5cb38372dbb8a768568189.png
The code
@Override
    public void onItemClick(View object, int n2) {
        try {
            object = (View) this.ourMenuItems.get(n2);
            if (!object.isProduct()) {
                if (this.materialFragmentActivityCallback != null) {
                    object = CatalogFragment.instance(object.getId(), object.getMenuTitle());
                    this.materialFragmentActivityCallback.beginFragmentManagerTransaction((Fragment)object, true);
                    return;
                }
            } else {
                Intent intent = new Intent(getActivity(),ProductActivity.class);
                intent.putExtra("PRODUCT_ID", object.getId());
                this.startActivity(intent);
            }
            return;
        }
        catch (Exception exception) {
            return;
        }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2019-04-14
@SimpleName

You yourself cast an object from the list to View . Even if you remove the calls and compile, it will still fall with a ClassCastException. Java has static typing.
What's the savings on variables? The fact that you named the variable object does not mean that you can shove anything into it. Select normal variables of the appropriate types, and you will be happy.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question