0
我編程在Java中,和我遇到以下異常來到...錯誤的Java類
"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)."
下面是相關的代碼。任何人都可以告訴是什麼導致這個異常?
//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);
}
請務必爲相關編程語言添加標籤。這樣,那些瞭解這種語言的人(Java?)就能夠找到你的問題。 – BergQuester
另外,我知道我們很多人會發布太多的代碼,但同時,如果你忽略了重要的代碼(這裏的主機代碼是'Host'?),我們根本無法提供幫助。 –
可能的[Java的重複 - 沒有可以訪問Foo類型的封閉實例](http://stackoverflow.com/questions/9560600/java-no-enclosing-instance-of-type-foo-is-accessible) – fabian