• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem while calling main() method.

 
Khushwinder Chahal
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am calling main() method of one class into other class like :



My parent class is a java frame and i have a button in it.
While clicking on this button i am calling main() as given above.
Its calling main() successfully and opening up a new child frame of Playshow class.
But when i close this child window my parent window is also closing.
Its exiting from the application.
I am not getting why its closing the whole application.
Please if anybody has any idea help me.
Thanks and Regards,
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15354
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By calling main() like that, you're starting the other application in the same JVM.

If the other application contains a call to System.exit(), it will terminate the whole VM, and your parent window will also be gone.

Solution: Don't call System.exit() in the other program, or start the other program in a separate JVM (which is a little bit more work then just calling its main() method).
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jesper Young:
Solution: Don't call System.exit() in the other program


General Solution: don't call System.exit() ever
 
Khushwinder Chahal
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jesper, Peter,

But I am not calling System.exit() in the other program.
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are doing for setDefaultCloseOperation(int) on your window? If it's EXIT_ON_CLOSE, then that explains it - closing the window will terminate the JVM. You should set it to HIDE_ON_CLOSE (or DISPOSE_ON_CLOSE if you know what you're doing).
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly you have set in the setDefaultCloseOperation() method for your JFrame?
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same Pinch Charles Lyons After a long time i face this situation again!
 
Khushwinder Chahal
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot of you guys.
It has solved my problem.
Thanks once again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic