java-error-no enclosing instance of type E is accessible

Source: Internet
Author: User

Recently in Java, when compiling an example of writing a book, because the code is only part of the book, so he complements an internal class. The result appears at compile time: No enclosing instance of type E is accessible.  Must qualify the allocation with an enclosing instance of type E (e.g. X.new A () where x is an instance of E). E refers to the inner class that I wrote.

As a hint, there is no instance of an accessible inner class E that must be assigned an instance of an appropriate inner class E (such as X.new A () and x must be an instance of E. look at this hint, I wonder, I have used new instantiation of this class, why not yet.

So Baidu Google a bit of relevant information. Originally I wrote the inner class is dynamic, that is, the beginning of the public class start. and the main program is public static class main. In Java, a static method in a class cannot invoke a dynamic method directly. Only an inner class is decorated as a static class, and then the member variables and member methods of the class can be called in a static class. So the solution is to change the public class to public static class.

Write down this question here, also on the side of the same problem of friends check

java-error-no enclosing instance of type E is accessible

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.