Question

i want to catch an IllegalStateException in Scala. Following code

val scene = new SceneDock

throws an IllegalStateException if an JavaFX-Application was not started before. This constructor is from the JemmyFX framework.

So i want to catch this Exception in the following way:

try{
 val scene = new SceneDock
 "running"}
catch{
 case e: IllegalStateException => { "stopped" } }

But it doesn't work. The output is always the IllegalStateException: Toolkit not initialized and it repeates until i terminate the application. Have already tried to catch Exception, and tried it with Java, but always the same result.

stack trace (it repeads until i terminate the app):

java.lang.IllegalStateException: Toolkit not initialized
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:155)
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:150)
at javafx.application.Platform.runLater(Platform.java:52)
at org.jemmy.fx.QueueExecutor.executeQueue(QueueExecutor.java:98)
at org.jemmy.action.AbstractExecutor.execute(AbstractExecutor.java:100)
at org.jemmy.fx.SceneList.getControls(SceneList.java:58)
at org.jemmy.lookup.PlainLookup.getChildren(PlainLookup.java:76)
at org.jemmy.lookup.AbstractLookup.refresh(AbstractLookup.java:172)
at org.jemmy.lookup.AbstractLookup$1.reached(AbstractLookup.java:141)
at org.jemmy.lookup.AbstractLookup$1.reached(AbstractLookup.java:137)
at org.jemmy.timing.Waiter.waitState(Waiter.java:78)
at org.jemmy.timing.Waiter.ensureState(Waiter.java:119)
at org.jemmy.lookup.AbstractLookup.wait(AbstractLookup.java:137)
at org.jemmy.lookup.AbstractLookup.get(AbstractLookup.java:250)
at org.jemmy.lookup.AbstractLookup.wrap(AbstractLookup.java:210)
at org.jemmy.dock.Dock.lookup(Dock.java:75)
at org.jemmy.fx.SceneDock.<init>(SceneDock.java:20)
at org.jemmy.fx.SceneDock.<init>(SceneDock.java:32)
at org.jemmy.fx.SceneDock.<init>(SceneDock.java:60)
at org.djemmysl.main.DjemmySL$class.applicationStatus(DjemmySL.scala:25)
at org.djemmysl.main.Main$.applicationStatus(Main.scala:3)
at org.djemmysl.main.Main$.main(Main.scala:6)
at org.djemmysl.main.Main.main(Main.scala)

java.lang.IllegalStateException: Toolkit not initialized
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:155)
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:150)
at javafx.application.Platform.runLater(Platform.java:52)
at org.jemmy.fx.QueueExecutor.executeQueue(QueueExecutor.java:98)
at org.jemmy.action.AbstractExecutor.execute(AbstractExecutor.java:100)
at org.jemmy.fx.SceneList.getControls(SceneList.java:58)
at org.jemmy.lookup.PlainLookup.getChildren(PlainLookup.java:76)
at org.jemmy.lookup.AbstractLookup.refresh(AbstractLookup.java:172)
at org.jemmy.lookup.AbstractLookup$1.reached(AbstractLookup.java:141)
at org.jemmy.lookup.AbstractLookup$1.reached(AbstractLookup.java:137)
at org.jemmy.timing.Waiter.waitState(Waiter.java:78)
at org.jemmy.timing.Waiter.ensureState(Waiter.java:119)
at org.jemmy.lookup.AbstractLookup.wait(AbstractLookup.java:137)
at org.jemmy.lookup.AbstractLookup.get(AbstractLookup.java:250)
at org.jemmy.lookup.AbstractLookup.wrap(AbstractLookup.java:210)
at org.jemmy.dock.Dock.lookup(Dock.java:75)
at org.jemmy.fx.SceneDock.<init>(SceneDock.java:20)
at org.jemmy.fx.SceneDock.<init>(SceneDock.java:32)
at org.jemmy.fx.SceneDock.<init>(SceneDock.java:60)
at org.djemmysl.main.DjemmySL$class.applicationStatus(DjemmySL.scala:25)
at org.djemmysl.main.Main$.applicationStatus(Main.scala:3)
at org.djemmysl.main.Main$.main(Main.scala:6)
at org.djemmysl.main.Main.main(Main.scala)
Was it helpful?

Solution

The instantiation SceneDock wait a little (10 sec by default, i guess) until a jemmy fx application is launched. During this wait, it lookups periodically (each 100ms by default) if a window have been opened by executing a task in the javafx thread (using Platform.runLater(Runnable)).

Invoking Platform.runLater(Runnable) when no application have been launched, a java.lang.IllegalStateExceptionis thrown, caught and print to the error output:

java.lang.IllegalStateException: Toolkit not initialized
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:153)
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:148)
    ...

If no application have been done after a while, you should get a org.jemmy.TimeoutExpiredException:

org.jemmy.TimeoutExpiredException: State 'Waiting for 1 javafx.scene.Scene controls to be found adhering to org.jemmy.lookup.Any@65e7c41f' has not been reached in 10000 milliseconds
at org.jemmy.timing.Waiter.ensureState(Waiter.java:121)
at org.jemmy.lookup.AbstractLookup.wait(AbstractLookup.java:138)
    ...

I get this behavior with the following code :

import org.jemmy.TimeoutExpiredException;
import org.jemmy.fx.SceneDock;
import org.junit.Test;

public class TestX {

    @Test
    public void notInitializedToolkit() {
        try {
            new SceneDock();

        } catch (TimeoutExpiredException e) {
            System.err.println("The application have not been launched");
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top