-No enclosing instance of type Test is accessible. Must qualify the allocation with a enclosing instance of type Test (e.g. X.new A () where x
is an instance of Test).
public class Test {public
static void Main (string[] args) {
test test = new test ();
Beans XM = test.new Beans ();
}
public class beans{
}
}
X refers to the inner class that I wrote.
According to the hint , there is no instance of an accessible internal class test, and an instance of the appropriate internal class test must be assigned (such as X.new A (), x must be an instance of test. looking at this hint, I wonder, I have already instantiated this class with new, why not yet.
So Baidu Google a bit about the relevant information. The inner Class I wrote is dynamic, which begins with the public class. The main program is public static class main. In Java, a static method in a class cannot call a dynamic method directly. Only an inner class is decorated as a static class, and then the member variable and member method of the class can be invoked in a static class. So the workaround is to change public class to public static class.
or change to the above new Test (). New Beans ():
Of course, if you want to look less bizarre, you can also write another method to instantiate the inner class, and then use an instance of the external class to invoke the method