• Post Reply Bookmark Topic Watch Topic
  • New Topic

RUn time exception  RSS feed

 
bikasit babu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class A{
A a1 = new A();
A(){
System.out.println("Hello");
public static void main(String args[])
{
A a1 = new A();
System.out.println("Hello");
}
}
why this program gives run time exception?
exception throw as Exception in thread "main" java.lang.StackOverflowError
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the exact exception?

Look at the exception name and the stack trace.

Look at the javadocs for the exception. The explain when it is thrown.

 
dennis deems
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint: how many objects are created when A is instantiated?
 
bikasit babu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:What is the exact exception?

Look at the exception name and the stack trace.

Look at the javadocs for the exception. The explain when it is thrown.


Exception in thread "main" java.lang.StackOverflowError
 
dennis deems
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So tell us about StackOverflowError. What have you discovered about this error? What causes it to be thrown? Do you see the problem in class A that brings this situation about?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bikasit babu wrote:
Jeff Verdegan wrote:What is the exact exception?

Look at the exception name and the stack trace.

Look at the javadocs for the exception. The explain when it is thrown.


Exception in thread "main" java.lang.StackOverflowError


And did you look at the stack trace, which shows you what called what next called what after that?

Between the name of the exception, its javadocs (which you read closely and carefully, right), and looking at the stack trace, you should have a pretty good idea what's happening.

If not, what exactly, precisely, and in detail do you not understand?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, and welcome to the Ranch!
 
bikasit babu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dennis Deems wrote:So tell us about StackOverflowError. What have you discovered about this error? What causes it to be thrown? Do you see the problem in class A that brings this situation about?

hey can you tell me whats happening inthat program .ihave checked everywhere .but i just cant get it
 
dennis deems
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a simple example that is very similar to your problem:



What happens when we call the method tellMeTheTime?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bikasit babu wrote:
Dennis Deems wrote:So tell us about StackOverflowError. What have you discovered about this error? What causes it to be thrown? Do you see the problem in class A that brings this situation about?

hey can you tell me whats happening inthat program


That's not how it worked.

.ihave checked everywhere .but i just cant get it


So, since you "checked everywhere", that means you looked at the javadocs, you googled, you looked at the stack trace, and you looked at the exception's name.

So, of all that stuff you looked at, what specifically are you not undertsanding?

You need to ShowSomeEffort(⇐click) and TellTheDetails.(⇐click)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!