• 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

I get a runtime error when using static Inner Class -- pls explain.

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
i tried to execute a program with static inner classes and tried to access the enclosing instance's static variable.
it compiles fine. but gives
"Exception in Thread "main" java.lang.VerifyError (class: myclass method: main signature: (LJava/lang/String V) Expecting to find uninitialized object on stack.
here is the code which created the above error at runtime.
class myouter{
int i ;
static int j;
myouter(){
System.out.println("Inside myouter()");
i =2;
j=3;
System.out.println("i is : "+i);
System.out.println("j is : "+j);
}
static class myinner{
myinner(){
System.out.println("Inside myinner()");
System.out.println("j is : "+j);
}//end of myinner()
}//end of myinner...
}
public class myclass{
public static void main(String args[]){
myouter.myinner in = new myouter().new myinner();
}//end of main
}
can anyone explain what is wrong with my code please? what am i missing ??
Thanks,
Sunitha. S
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your code statement:
myouter.myinner in = new myouter().new myinner();
is the way to construct a member inner class, not
a static nested top-level class instance. As I recall, you want
myouter.myinner in = new myouter.myinner() ;
Bill
 
Sunitha Sounderrajan
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bill..
i also learnt that the static inner class can be called as follows...
myouter.myinner in = new myouter.myinnner();
Thanks,
Sunitha. S


[This message has been edited by Sunitha Sounderrajan (edited October 08, 2000).]
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sunitha Sounderrajan,
I tried your code with
" myouter.myinner in = new myouter().new myinner();"
but I do not encounter error as you said.
Both "myouter.myinner in = new myouter().new myinner();"
and "myouter.myinner in = new myouter.myinner();"
give the same result.
why?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic