Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why StackOverowError ??

 
naveen yadav
Ranch Hand
Posts: 384
Java MyEclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why there is StackOverowError ??





naveen
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
naveen yadav
Ranch Hand
Posts: 384
Java MyEclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3159
33
Google App Engine Java Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 384
Java MyEclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys . i got it now.
 
Aniket S. Kulkarni
Ranch Hand
Posts: 87
Android Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if the issue is resolved then click on the "Resolved" button.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic