Daniel Daniel - 5 months ago 73
Java Question

Java: "error: cannot access" the interface

So I have this

Annotator
interface:

public interface Annotator {
String getViewName();

View getView(TextAnnotation var1) throws AnnotatorException;

String[] getRequiredViews();
}


which is extended by
GazetteerViewGenerator
:

public class GazetteerViewGenerator extends Annotator {
public static final GazetteerViewGenerator gazetteersInstance;
...


The issue is that when I create an object of
GazetteerViewGenerator
and cast into
Annotator
it gives me errors, which is really weird:

public class MyCuratorClient {
public static Annotator gazetteers = (Annotator) GazetteerViewGenerator.gazetteersInstance;
...


and here is the error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project Illinois-Combined-Coref: Compilation failure
[ERROR] /Users/danielk/ideaProjects/Illinois-Combined-Coref/src/main/java/edu/illinois/cs/cogcomp/lbj/coref/util/MyCuratorClient.java:[25,38] error: cannot access Annotator
[ERROR] -> [Help 1]
[ERROR]


Any ideas where I am going wrong?

Answer

A java class implements an interface rather than extends it.

You should have used this class definition:

public class GazetteerViewGenerator implements Annotator {
    public static final GazetteerViewGenerator gazetteersInstance;
    ... 
}