File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Problem while calling main() method. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem while calling main() method." Watch "Problem while calling main() method." New topic
Author

Problem while calling main() method.

Khushwinder Chahal
Ranch Hand

Joined: Oct 03, 2007
Posts: 128
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,


Khushwinder
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

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).


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Originally posted by Jesper Young:
Solution: Don't call System.exit() in the other program


General Solution: don't call System.exit() ever


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Khushwinder Chahal
Ranch Hand

Joined: Oct 03, 2007
Posts: 128
Hi Jesper, Peter,

But I am not calling System.exit() in the other program.
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
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).


Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

What exactly you have set in the setDefaultCloseOperation() method for your JFrame?


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Same Pinch Charles Lyons After a long time i face this situation again!
Khushwinder Chahal
Ranch Hand

Joined: Oct 03, 2007
Posts: 128
Thanks a lot of you guys.
It has solved my problem.
Thanks once again.
 
wood burning stoves
 
subject: Problem while calling main() method.
 
Similar Threads
How to Close multiple child windows from a parent window
Dialogs windows not displaying properly
Refreshing parent window
Implementing the child window in JSF.
Frames