File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes StackOverflowError error at Runtime  :( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "StackOverflowError error at Runtime  :(" Watch "StackOverflowError error at Runtime  :(" New topic

StackOverflowError error at Runtime :(

Amit Das
Ranch Hand

Joined: Mar 05, 2005
Posts: 206
i'm getting a StackOverflowError at runtime....plz guide me why....

/*since 'an' is an instance reference variable for class Anonymous, i've created an instance of class Anonymous, in the main(), which accesses the instance variable 'an' and since it refers an object of the anonymous class instance, i call the method call() by using it.*/

plz help me out,,
Mihai Alexe

Joined: Apr 13, 2005
Posts: 19
The problem with your code is that the Anonymous default constructor gets called somewhat "recursively". When you are calling the Anonymous constructor inside main() (i.e. new Anonymous()), the component objects get initialized first. That is, the constructor gets called again, because the an objects [of type Anonymous as well] needs to be assigned its value before the constructor finishes. There you go - an infinite constructor call chain - eventually ending in a StackOverflowException. I used the IBM JDK as well, and it refused to load my class - perhaps this compiler is a little "smarter" than the SUN javac

SCJP for Java 1.4<br />SCBCD for J2EE 1.3
I agree. Here's the link:
subject: StackOverflowError error at Runtime :(
jQuery in Action, 3rd edition