Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java class compile time error "Cannot access interface"

I have an interface stores which has two methods getName() and getAddres(), and I have a class Market which implements Stores This is my code:

public interface Stores {
    public String getName();
    public String getAddress();
}

And the concrete class:

public class Market implements Stores {
    private String name;
    private String address;
    private int size;

    public Market(String name, String address, int size) {
        this.name = name;
        this.address = address;
        this.size = size;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getAddress() {
        return address;
    }

    public int getSize() {
        return size;
    }
}

I get errors in constructor regarding this.name=name, this.address=address and this.size=size saying that "Cannot access stores". Any ideas why?

like image 627
Levon Asatryan Avatar asked Dec 27 '16 13:12

Levon Asatryan


2 Answers

It's 2020 and I'm still having this issue in IntelliJ Idea. Sometimes a restart of the IDE is enough but today I had to File -> Invalidate Caches / Restart in order for it to recognise a new interface that I had written. Refused to recognise it in package local as well as when explicitly imported to other packages.

like image 119
Skrrp Avatar answered Oct 29 '22 04:10

Skrrp


I've faced the same issue in Intetlij. It was very weird for me what had helped:

I had to change any value in pom.xml (I've used "mainClass"). Then change it back (since value was correct). Project view was refreshed and class starts to see the interface.

like image 10
Przemek Avatar answered Oct 29 '22 05:10

Przemek