0

I am programming in Java, and I came across the following exception...

"No enclosing instance of type Host is accessible. Must qualify the allocation with an enclosing instance of type Host (e.g. x.new A() where x is an instance of Host)." 

Here is the relevant code. Any anyone tell what is causing this exception?

//Creating john     
    Employee john =new Employee(Name,Address,Age,Salary);
    //closing the scanner
    in.close();

    john.info();
}
class Employee
{
    //variables
    private String name ="";
    private String address="";
    private double salary=0.0;
    private int age=0;

    //constructor
    public Employee(String n, String add,int a, double s )
    {
        name = n;
        address = add;
        salary = s;
        age = a;        
    }
    public void info()
    {
        System.out.println(name);
        System.out.println(address);
        System.out.println(age);
        System.out.println(salary);
    }
Joel
  • 4,732
  • 9
  • 39
  • 54
Jim Moak
  • 41
  • 1
  • 1
  • 2
  • Please be sure to add a tag for the programming language in question. That way people who know that language (Java?) are able to find your questions. – BergQuester Aug 02 '13 at 17:23
  • 3
    Also, I know a lot of us give flak for posting too much code, but at the same time, if you leave out important code (where the heck is `Host`?), we can't help at all. – Dennis Meng Aug 02 '13 at 17:25
  • Possible duplicate of [Java - No enclosing instance of type Foo is accessible](http://stackoverflow.com/questions/9560600/java-no-enclosing-instance-of-type-foo-is-accessible) – fabian Mar 04 '16 at 00:39

1 Answers1

0

The error pretty much explains it all. You probably have a non-static inner class in Host and you're trying to instantiate it in a static context (i.e. Host.Inner obj = new Host.Inner()). You can either make that class static or instantiate it with an instance of the outer class. All this information is available in the docs. A simple google search would have revealed that.

Imirak
  • 1,323
  • 11
  • 21