Daniel Daniel - 1 year ago 168
Java Question

Java: "error: cannot access" the interface

So I have this


public interface Annotator {
String getViewName();

View getView(TextAnnotation var1) throws AnnotatorException;

String[] getRequiredViews();

which is extended by

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

The issue is that when I create an object of
and cast into
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]

Any ideas where I am going wrong?

Answer Source

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;