Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

exception at runtime  RSS feed

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


why does it produce an exception at runtime??? Help?

EJavaGuruPrivate2.main({ });
    Exception occurred.

 
Bartender
Posts: 2178
46
Firefox Browser IntelliJ IDE Java Linux Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The constructor in Course creates a new instance of Course (line 4) which results in the constructor being called. Then...
The constructor in Course creates a new instance of Course (line 4) which results in the constructor being called. Then...
The constructor in Course creates a new instance of Course (line 4) which results in the constructor being called. Then...
The constructor in Course creates a new instance of Course (line 4) which results in the constructor being called. Then...
The constructor in Course creates a new instance of Course (line 4) which results in the constructor being called. Then...
The constructor in Course creates a new instance of Course (line 4) which results in the constructor being called. Then...
The constructor in Course creates a new instance of Course (line 4) which results in the constructor being called. Then...
The constructor in Course creates a new instance of Course (line 4) which results in the constructor being called. Then...
The constructor in Course creates a new instance of Course (line 4) which results in the constructor being called. Then...
The constructor in Course creates a new instance of Course (line 4) which results in the constructor being called. Then...
The constructor in Course creates a new instance of Course (line 4) which results in the constructor being called. Then...
...

Which leads to StackOverflowError.
 
lowercase baba
Bartender
Posts: 12627
50
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it often helps if you post the exact error - or at least, th beginning of it.  When I run this code, I get this:

C:\slop>java EJavaGuruPrivate2
Exception in thread "main" java.lang.StackOverflowError
        at Course.<init>(Course.java:4)
        at Course.<init>(Course.java:4)
        at Course.<init>(Course.java:4)
        at Course.<init>(Course.java:4)
        at Course.<init>(Course.java:4)
        at Course.<init>(Course.java:4)

It is possible your settings don't let you see the beginning of the errors.  If you are using Windows, the cmd window by default only has bout 100 lines of buffer. You can right-click the title bar on it, go to 'properties', and change the "Screen Buffer Size" height to something bigger. I have mine set to 9999.

Once you do that, you can scroll up and see the beginning of the error message. That first line tells you exactly what the problem is, once you learn how to interpret it. "StackOverflowError" means you've called too many methods inside each other. Almost always it means you have a method calling itself, either directly or indirectly. As Pawel pointed out, your constructor for your Course class creates a new Course object, which calls the constructor...

edit - if you are not using the cmd window to compile and run your code, I would suggest you start doing so. In the early stages of programming, it really is helpful to see what's going on and helps you learn some of subtleties of the language.
 
Kamila Bertran
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it, thanks !
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!