简体   繁体   中英

running main method from other class

I've been trying to run main method from other class. I know that swing is single threaded. So i'm using this code

private static void runUpdate(){
    SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
        String[] args1={"10"};
        Update.main(args1);
    }
});
}

private void updateButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
    runUpdate();
}  

this code is in InventoryMgr class and i want to run main method from Update class.

I got StackOverFlowError

Look through the stack trace in your StackOverFlowError. It will show you what method called what, and on what line number. The problem is that your main() calls a method which calls a method which calls main() which calls ...

The solution is to pull the functionality you need to repeat out of main() and put it in a separate method. Then you can call it without causing infinite recursion.

It is legal to call main(), and it is not really special other than the JVM will call it to begin your program. However, it is unusual to actually want to call main() again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM