Java secondary not public Class usage produces error "Type is not Visible" even if accessed methods are public in Main class
I have a Main.java file:
public class Main{
private EntityDrawer entityDrawer;
public void setEntityDrawer(EntityDrawer entityDrawer) {
this.entityDrawer = entityDrawer;
}
public EntityDrawer getEntityDrawer() {
return entityDrawer;
}
}
class EntityDrawer {
private Empleado empleado;
开发者_开发技巧
public Empleado getEmpleado() {
return empleado;
}
public void setEmpleado(Empleado empleado) {
this.empleado = empleado;
}
}
If I try to access from another file, it works if I only try to access the entityManager:
Main main = new Main();
main.getEntityDrawer(); // NO PROBLEM!
But if I try to access one of the attributes (even if public) from entityManager, it does not work:
Main main = new Main();
main.getEntityDrawer().getEmpleado(); // Gives error "The type EntityDrawer is not visible"
I cannot understand why is happening, could someone give me some insight into this issue?...
I assume you are trying to use a package local class EntityDrawer
in another package, which you cannot do.
Try making the class public
Make the class public
or move the calling class to same package.
I too got annoyed with this problem, I removed unnecessary jar files and add only required jar files in the classpath. Sometimes if you put redundant jar files in the class path will leads to conflicting of the jar files and that will shows the error(like "the type org.apache.lucene.index.DirectoryReader is not visible").
Thank you.
精彩评论