Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?...

like image 971
will824 Avatar asked Apr 28 '11 16:04

will824


2 Answers

I assume you are trying to use a package local class EntityDrawer in another package, which you cannot do.

Try making the class public

like image 77
Peter Lawrey Avatar answered Sep 20 '22 23:09

Peter Lawrey


Make the class public or move the calling class to same package.

like image 34
kdabir Avatar answered Sep 23 '22 23:09

kdabir