AlterionX
AlterionX

Reputation: 81

Why is the interface method unresolvable?

I have code that calls on a interface I called "ListDescribable" for use with a custom ArrayAdapter.

The Interface is declared as follows:

public interface ListDescribable {
    String getCalledName();
    String getDescriptor();
    boolean isActive();
    void toggle();

}

I call on the interface methods here:

 listEntry = new DescribableEntry();
 listEntry.broadcastSwitch =(Switch) row.findViewById(R.id.list_entry_switch);

...

ListDescribable entry = data[position];
listEntry.broadcastSwitch.setChecked(entry.isActive());

I try to call isActive(), but the ide tells me that isActive cannot be resolved. Why does this happen? How can I fix it?

edit:

DescribableEntry code:

static class DescribableEntry {
    Switch broadcastSwitch;
    TextView itemName;
    TextView itemDescriptor;
    ImageView blueStatus;
}

Edit: DescribableEntry is not the ListDescribable. Under no circumstance does the ListDescribable methods getcalled on a DescribableEntry object.

as per request, data[] is an array of ListDescribable objects, declared in object initalization as a field variable. The class being used in the project is for an interrupter, which is currently a placeholder:

public boolean isActive() { return false; }

Upvotes: 0

Views: 84

Answers (2)

Iamsomeone
Iamsomeone

Reputation: 323

You need to make your class implements the interface, otherwise the two will be completely separated.

static class DescribableEntry implements ListDescribable
{
... implement all interface methods here ...
}

You can read more about interfaces here: https://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html

Upvotes: 1

Alexandre Gautier
Alexandre Gautier

Reputation: 29

Your "data" table should implements "ListDescribable"

If "data[position]" is of type "DescribableEntry", so "DescribableEntry" should implements ListDescribable", and his methods.

Upvotes: 1

Related Questions