Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in constructor

 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i m trying a code, and as i think it should prints 10 infinite times, but it is not..
here is the code:

it printing
10 for some lines and than.
"at A.<init><A.java:8>"
"at A.<init><A.java:13>"
number of times.

i don't know why out put is this??
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can you please post complete output? At least first few lines and last few lines?

I suspect that you are getting a OutOfMemoryError due to calling same constructor inside itself.

I hope this helps.
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is the complete output..


10
10
10
10
10
10
10
10
10
10
<snip: 3499 in total>
Exception in thread "main" java.lang.StackOverflowError
at sun.nio.cs.SingleByteEncoder.encodeArrayLoop(Unknown Source)
at sun.nio.cs.SingleByteEncoder.encodeLoop(Unknown Source)
at java.nio.charset.CharsetEncoder.encode(Unknown Source)
at sun.nio.cs.StreamEncoder.implWrite(Unknown Source)
at sun.nio.cs.StreamEncoder.write(Unknown Source)
at java.io.OutputStreamWriter.write(Unknown Source)
at java.io.BufferedWriter.flushBuffer(Unknown Source)
at java.io.PrintStream.write(Unknown Source)
at java.io.PrintStream.print(Unknown Source)
at java.io.PrintStream.println(Unknown Source)
at A.<init>(A.java:7)
at A.<init>(A.java:13)
at A.<init>(A.java:8)
at A.<init>(A.java:13)
at A.<init>(A.java:8)
at A.<init>(A.java:13)
at A.<init>(A.java:8)
at A.<init>(A.java:13)
<snip: lines 8 and 13 repeat for 90 lines>
at A.<init>(A.java:8)
at A.<init>(A.java:13)
at A.<init>(A.java:8)
at A.<init>(A.java:13)
at A.<init>(A.java:8)
at A.<init>(A.java:13)
at A.<init>(A.java:8)
at A.<init>(A.java:13)
at A.<init>(A.java:8)
at A.<init>(A.java:13)
at A.<init>(A.java:8)10
10
10
10
10
10
10
10
10
10
10
<snip: 124 in total>

at A.<init>(A.java:13)
at A.<init>(A.java:8)
at A.<init>(A.java:13)
at A.<init>(A.java:8)
at A.<init>(A.java:13)
at A.<init>(A.java:8)
at A.<init>(A.java:13)
<snip: lines 8 and 13 repeat for 898 lines>
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Root cause is same as I mentioned - calling a constructor within itself. Hence, program crashed with throwing StackOverflowError as it can be seen in output:

Exception in thread "main" java.lang.StackOverflowError
at sun.nio.cs.SingleByteEncoder.encodeArrayLoop(Unknown Source)
at sun.nio.cs.SingleByteEncoder.encodeLoop(Unknown Source)
at java.nio.charset.CharsetEncoder.encode(Unknown Source)
at sun.nio.cs.StreamEncoder.implWrite(Unknown Source)
at sun.nio.cs.StreamEncoder.write(Unknown Source)
at java.io.OutputStreamWriter.write(Unknown Source)
at java.io.BufferedWriter.flushBuffer(Unknown Source)
at java.io.PrintStream.write(Unknown Source)
at java.io.PrintStream.print(Unknown Source)
at java.io.PrintStream.println(Unknown Source)
at A.<init>(A.java:7)
at A.<init>(A.java:13)
at A.<init>(A.java:8)
at A.<init>(A.java:13)
at A.<init>(A.java:8)
at A.<init>(A.java:13)
at A.<init>(A.java:8)
at A.<init>(A.java:13)
...
 
Rob Spoor
Sheriff
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Punit, are you crazy? You posted over 4000 lines of output! I've removed quite a lot of those while still maintaining the relevant information.

Anayonkar is right. When you create a new A(), that creates a new A(10). That in turn creates a new A(), which again creates a new A(10). This continues until a StackOverflowError is thrown.
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay..thank you...
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am sorry for that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic