• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Problem while calling main() method.

 
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,
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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).
 
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.
 
Author
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).
 
Ranch Hand
Posts: 3389
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: 3389
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.
 
machines help you to do more, but experience less. Experience this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic