Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with System.exit(0)"  RSS feed

 
Elim Banda
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the error im getting when I try and run my java program in Dr java

"the interactions window was terminated by the call to System.exit(0)"

The program runs briefly and then closes, it works properly when I remove the System.exit(0)" what is the purpose of this command and why do the examples in the text book have it. Please look at the code below

____________________________________________________________________________
 
Liutauras Vilda
Marshal
Posts: 4624
316
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Meki Banda.

Please check how to UseCodeTags (<- link) properly. I see you tried, thank you for that.
 
Liutauras Vilda
Marshal
Posts: 4624
316
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Meki Banda wrote:The program runs briefly and then closes, it works properly when I remove the System.exit(0)"

Please provide a bit more details based on that quoted sentence you wrote. What do you mean by program works properly when you remove System.exit(0)? What abnormal things happens with System.exit(0)?
 
Elim Banda
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote:
Meki Banda wrote:The program runs briefly and then closes, it works properly when I remove the System.exit(0)"

Please provide a bit more details based on that quoted sentence you wrote. What do you mean by program works properly when you remove System.exit(0)? What abnormal things happens with System.exit(0)?
\

Try run the code in Dr Java it takes a few minutes to download. The program crashes abruptly and there is no time to see the output.
 
Liutauras Vilda
Marshal
Posts: 4624
316
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Meki Banda wrote:"the interactions window was terminated by the call to System.exit(0)"
I'm sorry, I completely missed that. I'm not sure about that error/information message, but I suspect this could be related with your programming environment DrJava which I have to admit never tried it.

About the System.exit used in particullary together with JoptionPane's you can google it, there are lots of answers. Please start here.
 
Elim Banda
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote:
Meki Banda wrote:"the interactions window was terminated by the call to System.exit(0)"
I'm sorry, I completely missed that. I'm not sure about that error/information message, but I suspect this could be related with your programming environment DrJava which I have to admit never tried it.

About the System.exit used in particullary together with JoptionPane's you can google it, there are lots of answers. Please start here.


please look at the attachment
Capture1.PNG
[Thumbnail for Capture1.PNG]
 
Liutauras Vilda
Marshal
Posts: 4624
316
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I mentioned, it is just a information message. I see there is a tab "Console" at the bottom, so click that and likely you'll see your program's output.
The possible reasons of using or not using System.exit with JoptionPane please check in the google search link I provided. You could find long explanations of it.

Also you do have book where you found example which uses it. What is said in your book about it and which book you're reading?
 
Elim Banda
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote:As I mentioned, it is just a information message. I see there is a tab "Console" at the bottom, so click that and likely you'll see your program's output.
The possible reasons of using or not using System.exit with JoptionPane please check in the google search link I provided. You could find long explanations of it.

Also you do have book where you found example which uses it. What is said in your book about it and which book you're reading?


Thanks for your help
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It may be worth mentioning that this is just one reason why it's generally NOT a good idea to use System.exit().

So perhaps it's worth asking: Why did you use it?

Winston
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!