0

I have one class in which i am calling another class's main1 method.

Thread t=new Thread(new Runnable() {
    @Override
    public void run() {
       temp eqsj=new temp(null, null, false, false);
       String[] arguments=jtextfield1.getText().toString().split(" ");
       eqsj.main1(arguments);
       JOptionPane.showMessageDialog(new JFrame(), "Report generated"); 
    }
    });
    t.start();

That temp class implements runnable, so after main1 is called from above code, and it will execute run() method of temp class, which is running fine.

Problem is :: When run method gets completed, the application is getting terminated and not returning back where main1 is called and due to that it is not implementing the remaining lines of code which is:

JOptionPane.showMessageDialog(new JFrame(), "Report generated");

  • [`SwingUtilities.invokeAndWait(Runnable)`](https://docs.oracle.com/javase/7/docs/api/javax/swing/SwingUtilities.html#invokeAndWait(java.lang.Runnable)) – Elliott Frisch Jun 13 '17 at 11:03
  • Actually that temp class's main which I am calling does not implements runnable. In main of temp class i am using invokeandwait and passing another class(3rd class in scene)constructor which actually implements runnable. – Vivek Pandita Jun 13 '17 at 11:08
  • so this SwingUtilities.invokeAndWait(Runnable) i have already used – Vivek Pandita Jun 13 '17 at 11:09
  • Does main1 throw an exception? You can and probalby should pass 'null' instead of using `new JFrame()`, that could be causing your problem. Maybe add a println after the call to main1. – matt Jun 13 '17 at 11:26
  • If nothing else, show us `main1` do you have a `System.exit` call? – matt Jun 13 '17 at 11:29
  • Perhaps you want to wait for the thread to finish? See my answere here: https://stackoverflow.com/questions/24253298/thread-wont-naturally-exit-at-end-of-run/24253574#24253574 – ldmtwo Jun 13 '17 at 20:03
  • Thanks matt, yes there was System.exit call – Vivek Pandita Jun 14 '17 at 07:12

0 Answers0