• Plans & Pricing
  • Log in
  • Get started
  • WordPress Hosting
  • WordPress for Agencies
  • Become an Affiliate
  • Domain Names
  • AI Website Builder
  • Website Builder
  • Create a Blog
  • Newsletter
  • Professional Email
  • Website Design Services
  • Commerce
  • WordPress Studio
  • Enterprise WordPress 
  • Overview
  • WordPress Themes
  • WordPress Plugins
  • WordPress Patterns
  • Google Apps
  • Support Center
  • WordPress News
  • Business Name Generator
  • Logo Maker
  • Discover New Posts
  • Popular Tags
  • Blog Search
Get started
  • Sign up
  • Log in
About
  • Plans & Pricing
Products
  • WordPress Hosting
  • WordPress for Agencies
  • Become an Affiliate
  • Domain Names
  • AI Website Builder
  • Website Builder
  • Create a Blog
  • Newsletter
  • Professional Email
  • Website Design Services
  • Commerce
  • WordPress Studio
  • Enterprise WordPress  
Features
  • Overview
  • WordPress Themes
  • WordPress Plugins
  • WordPress Patterns
  • Google Apps
Resources
  • Support Center
  • WordPress News
  • Business Name Generator
  • Logo Maker
  • Discover New Posts
  • Popular Tags
  • Blog Search
Jetpack App
  • Learn more
  • Support Center
  • Guides
  • Courses
  • Forums
  • Contact
Search
  • Support Center
  • Guides
  • Courses
  • Forums
  • Contact
Forums / Must qualify the allocation with an enclosing instance of type classname

Must qualify the allocation with an enclosing instance of type classname

  • Unknown's avatar
    rubanraj · Member · Aug 21, 2014 at 12:20 pm
    • Copy link Copy link
    • Add topic to favorites Add topic to favorites
    public class GeoLocation {
        public static void main(String[] args) throws InterruptedException {
            int size = 10;
    
            // create thread pool with given size
            ExecutorService service = Executors.newFixedThreadPool(size); 
    
            // queue some tasks
            for(int i = 0; i < 3 * size; i++) {
                service.submit(new ThreadTask(i));   //wrong syntax
            }
    
            // wait for termination
            service.shutdown();
            service.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
        }
    
        class ThreadTask implements Runnable {
            private int id;
    
            public ThreadTask(int id) {
                this.id = id;
            }
    
            public void run() {
                System.out.println("I am task " + id);
            }
        }
    
    }

    if we execute the following code.it will throw us the error “No enclosing instance of type GeoLocation is accessible. Must qualify the allocation with an enclosing instance of type GeoLocation (e.g. x.new A() where x is an instance of GeoLocation)”.

    This error happens because in the above code i am trying to create an instance of an inner class service.submit(new ThreadTask(i)); without creating instance of main class.

    To resolve this issue please create instance of main class first:

    GeoLocation outer = new GeoLocation();
    Then create instance of class you intended to call, as follows:

    service.submit(outer.new ThreadTask(i));

    Since main method is static and i try to call inner class from here i have to do like this.if your main method is non static you dont have to follow this.

    The blog I need help with is: (visible only to logged in users)

  • The topic ‘Must qualify the allocation with an enclosing instance of type classname’ is closed to new replies.

Tags

  • login

About this topic

  • In: Support
  • 1 participant
  • 0 replies
  • Last activity 11 years
  • Latest reply from rubanraj

Couldn't find what you needed?

Contact us

Contact us

Get answers from our AI assistant, with access to 24/7 expert human support on paid plans.

Browse our guides

Browse our guides

Find step-by-step solutions to common questions in our comprehensive guides.

WordPress.com

Products
  • WordPress Hosting
  • WordPress for Agencies
  • Become an Affiliate
  • Domain Names
  • AI Website Builder
  • Website Builder
  • Create a Blog
  • Professional Email
  • Website Design Services
  • WordPress Studio
  • Enterprise WordPress
Features
  • Overview
  • WordPress Themes
  • WordPress Plugins
  • WordPress Patterns
  • Google Apps
Resources
  • WordPress.com Blog
  • Business Name Generator
  • Logo Maker
  • WordPress.com Reader
  • Accessibility
  • Remove Subscriptions
Help
  • Support Center
  • Guides
  • Courses
  • Forums
  • Contact
  • Developer Resources
Company
  • About
  • Press
  • Terms of Service
  • Privacy Policy
  • Do Not Sell or Share My Personal Information
  • Privacy Notice for California Users
DeutschEspañolFrançaisBahasa IndonesiaItalianoNederlandsPortuguês do BrasilSvenskaTürkçeРусскийالعربيةעִבְרִית日本語한국어简体中文繁體中文English

Mobile Apps

  • Download on the App Store
  • Get it on Google Play

Social Media

  • WordPress.com on Facebook
  • WordPress.com on X (Twitter)
  • WordPress.com on Instagram
  • WordPress.com on YouTube

Automattic

Automattic
Work With Us
    • WordPress.com Forums
    • Sign up
    • Log in
    • Copy shortlink
    • Report this content
    • Manage subscriptions