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 Stack Over flow error when Instantiating Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply locked New topic

Stack Over flow error when Instantiating

Parameswaran Thangavel
Ranch Hand

Joined: Mar 01, 2005
Posts: 485
hi all
can any one tell me whats the problem in the below code

i am getting stack overflow erro when instantiating Temp1
new Temp1() gives me stackoverflow error

Stary Kapec
Ranch Hand

Joined: Dec 04, 2005
Posts: 81

Every time you create Temp1 instance you create another two Temp1 instances, and every time one of these two instances is created another two Temp1 instances are created and so on, and so on...
The circular association in your class causes the problem.
[ August 15, 2006: Message edited by: Jasiek Motyka ]
Sujittt Tripathyrr
Ranch Hand

Joined: Jun 21, 2006
Posts: 96

I am not getting any error.

can you please tell me where are you getting the error.

Stary Kapec
Ranch Hand

Joined: Dec 04, 2005
Posts: 81

Try to instantiate the class. Add the main method.

wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
You can fix the problem by adding "static" modifier

[ August 16, 2006: Message edited by: wise owen ]
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
This is a duplicate, with the same answer. Parameswaran, please don't post the same question in more than one forum here; it just wastes people's time when they respond to it without knowing it's already been answered elsewhere.

Followups go here.

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: Stack Over flow error when Instantiating
It's not a secret anymore!