This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I get a runtime error when using static Inner Class -- pls explain.
Sunitha Sounderrajan
Ranch Hand
Joined: Sep 12, 2000
Posts: 36
posted
0
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
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12269
1
posted
0
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
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).]
Bin Zhao
Ranch Hand
Joined: Oct 04, 2000
Posts: 73
posted
0
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?
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: I get a runtime error when using static Inner Class -- pls explain.