• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Not an enclosing class

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an outer class and a static inner class. It looks like this:
public class
OuterClass extends SomeClass
{
// Some code here
public static class
InnerClass extends SomeOtherClass
{
}
}
In another class (which is in another package), I'm trying to create an instance of inner class by doing
private OuterClass.InnerClass inst = null;
inst = new OuterClass.InnerClass(); //Getting error in this line
But the last line shows error. Compiler says "OuterClass is not an enclosing class".
I would appreciate any clues.
Thanks,
- Raja.
 
author
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're trying to make a static reference to a non-static variable. Make the inst variable static and it should compile OK...
 
Raja Kannappan
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. Declaring inst as static doesn't make any difference. I'm still getting the same error "Not an enclosing class: OuterClass".
Thanks,
- Raja.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Often the devil is in the details. Perhaps you should show us the real code, instead of this little sketch.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, agree.
I cut off the 'extends [Some]OtherClass, made a method foo, and it compiled well:
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Come on, Raja! Give us more details. I can not reproduce the error either. How are SomeClass and SomeOtherClass related?
 
Raja Kannappan
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. The skeleton compiled well for me (I didn't try the skeleton before posting it). But the original code has problems. I am still puzzled what the devil is. I can't post the code because it is too big. Anyway, I found another workaround for achieving my task.
So, thank you all for your responses,
- Raja.
 
reply
    Bookmark Topic Watch Topic
  • New Topic