Hallo, ich habe ein furchtbares Problem...:
übersichtliche Darstellung:
Beim ersten Klick auf den button gibts wunderbar eine "hallo"-Ausgabe in der Console.
Beim 2ten Klick jedoch, bekomme ich ne ganz böse IllegalThreadStateException:
(Gui2 entspricht hier B)
Ich habe gelesen, dass diese Exception geworfen wird, wenn der Thread A der gestartet wird (beim 2ten mal) noch nicht beendet ist. Aber das kann hier nicht sein. außerdem habe ich mit A.isAlive() vorher getestet ob er noch "lebt" und das tut er nicht! Trotzdem diese Exception.
Bin am verzweifeln, bitte um Hilfe !
Vielen Dank für Eure Mühe!
mfg
Chris
übersichtliche Darstellung:
Code:
Class A extends Thread{
public void run(){
syso("hallo");
}
}
Code:
Class B extends JFrame implements ActionListener{
JButton button = new JButton();
A halloThread = new A();
public B (){
this.button.addActionListener(this);
this.getContentPane.add(button);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource()==button){
halloThread.start();
}
}
public static void main(String[] args){
new B();
}
}
Beim ersten Klick auf den button gibts wunderbar eine "hallo"-Ausgabe in der Console.
Beim 2ten Klick jedoch, bekomme ich ne ganz böse IllegalThreadStateException:
Code:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalThreadStateException
at java.lang.Thread.start(Unknown Source)
at Gui2.actionPerformed(Gui2.java:322)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Ich habe gelesen, dass diese Exception geworfen wird, wenn der Thread A der gestartet wird (beim 2ten mal) noch nicht beendet ist. Aber das kann hier nicht sein. außerdem habe ich mit A.isAlive() vorher getestet ob er noch "lebt" und das tut er nicht! Trotzdem diese Exception.
Bin am verzweifeln, bitte um Hilfe !
Vielen Dank für Eure Mühe!
mfg
Chris