File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why StackOverowError ?? 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 "why StackOverowError ??" Watch "why StackOverowError ??" New topic
Author

why StackOverowError ??

naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

Why there is StackOverowError ??





naveen
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

You have recursive initialization calls- One in main which triggers a new instance creation and then in the class definition you have: CCL test = new CCL(); which leads to a instance creation call and this continues.
So you should be removing: CCL test = new CCL(); from your class definition


Mohamed Sanaulla | My Blog
naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

i didn't understand that. can you you elaborate ?

what i think is here how it flows :

when control on line 11-->
object instantiation say ob@1 starts here
line 3 executes object instantiation say ob@2 starts here
obj@2 proceeds to execute line 5 to 7.
obj@2 completes.
obj@1 initialize test var on line 3
obj@1 run constructor
obj@1 completes


where is recursion ??



naveen
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

naveen yadav wrote:i didn't understand that. can you you elaborate.

what i think is here how it flows :

when control on line 11-->
object instantiation say ob@1 starts here
line 3 executes object instantiation say ob@2 starts here
obj@2 proceeds to execute line 5 to 7.
obj@2 completes.
obj@1 completes.


where is recursion ??

Line 11 executes an object instantiation - this triggers line 3 to execute.
Line 3 again initiates an object instantiation - this triggers line 3 to execute. and this repeats.
The reason is that line 3 is executed everytime a new instance is created. So you see the recursion there.
Tomasz Sochanski
Ranch Hand

Joined: Jan 13, 2009
Posts: 47

naveen yadav wrote:i didn't understand that. can you you elaborate ?

where is recursion ??




Every call new Cert() creates an instance of Cert. One of Cert field is initiated as new Cert(), which causes creation of Cert object containing Cert field, which has to be instantiated as new Cert(), which again causes creation of new Cert() object, which has to have initialized all fields, especially this field which is created as new Cert(), which causes .... this is recursion ;)
naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

thanks guys . i got it now.
Aniket S. Kulkarni
Ranch Hand

Joined: Jun 15, 2011
Posts: 87

if the issue is resolved then click on the "Resolved" button.


Aniket Kulkarni
Oracle Certified Professional, Java SE 6 Programmer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why StackOverowError ??