1

IllegalThreadStateException が発生しています。

Eclipse のデバッガーではすべて問題ありませんが、Firefox でテストしようとすると失敗し始めます。Webページを更新した後、最初の実行は問題ありません。その例外が発生します。

コードは次のとおりです。

public void init() {
    try {           
        SwingUtilities.invokeAndWait(new Runnable() 
        {
            public void run() 
            {                   
                createGUI();
                createConnection();
            }
        });
    } 
    catch (Exception e) 
    { 
        System.err.println("createGUI didn't complete successfully");
        e.printStackTrace();
        System.err.println(e.toString());
    }
}


private void createConnection()
{       
    _connectionThread = ConnectionThread.getInstance();
    _connectionThread.setServer(getCodeBase().getHost());
    _connectionThread.start(); <------ Exception        
}

私はJavaが初めてですが、これは私の最初のアプレットです。私は何か間違ったことをしていることを知っていますが、それが何であるかを見つけることができません。

編集: コンソールから

java.lang.reflect.InvocationTargetException
at java.awt.EventQueue.invokeAndWait(Unknown Source)
at javax.swing.SwingUtilities.invokeAndWait(Unknown Source)
at com.onlinegame.gameclient.GameClient.init(GameClient.java:76)
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalThreadStateException
    at java.lang.Thread.start(Unknown Source)
    at com.onlinegame.gameclient.GameClient.createConnection(GameClient.java:175)
    at com.onlinegame.gameclient.GameClient.access$100(GameClient.java:34)
    at com.onlinegame.gameclient.GameClient$1.run(GameClient.java:81)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(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)
java.lang.reflect.InvocationTargetException
4

1 に答える 1

0
 _connectionThread = ConnectionThread.getInstance();

looks like ConnectionThread is a Singleton (is that true?) and extends Thread. If that is correct you may have a problem as a Thread can only be started once (Thread.start()). If you attempt to start the same Thread instance a second time, it will fail with a java.lang.IllegalThreadStateException.

To solve this, create a new Thread object on every request or cache the result of execution in the singletion. How to exactly implement that depends on what you want to achieve with the thread and the design of your app.

于 2012-11-12T11:08:24.887 に答える