Hallo, ich habe einen Fehler in meinen Code. Der Code soll ein vorhandenes VS Code Projekt automatisch öffnen. VS Code wird erfolgreich geöffnet doch bevor der erste Button angeklickt wird kommt diese Fehlermeldung:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalThreadStateException: Cannot call method from the event dispatcher thread
at java.desktop/java.awt.Robot.checkNotDispatchThread(Robot.java:764)
at java.desktop/java.awt.Robot.waitForIdle(Robot.java:757)
at org.sikuli.script.support.RobotDesktop.checkMousePosition(RobotDesktop.java:152)
at org.sikuli.script.support.RobotDesktop.smoothMove(RobotDesktop.java:141)
at org.sikuli.script.support.RobotDesktop.smoothMove(RobotDesktop.java:111)
at org.sikuli.script.Mouse.doMove(Mouse.java:317)
at org.sikuli.script.Mouse.move(Mouse.java:445)
at org.sikuli.script.Mouse.move(Mouse.java:390)
at org.sikuli.script.Screen.initScreens(Screen.java:164)
at org.sikuli.script.Screen.getNumberScreens(Screen.java:380)
at Main.click(Main.java:6212)
at Main.openVSProject(Main.java:6191)
at Main$93.actionPerformed(Main.java:3453)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1972)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2314)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:407)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
at java.desktop/java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:297)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6621)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3404)
at java.desktop/java.awt.Component.processEvent(Component.java:6386)
at java.desktop/java.awt.Container.processEvent(Container.java:2266)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4996)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4828)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4948)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4575)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4516)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2310)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2780)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4828)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:775)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:98)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:747)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:744)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.IllegalThreadStateException: Cannot call method from the event dispatcher thread
at java.desktop/java.awt.Robot.checkNotDispatchThread(Robot.java:764)
at java.desktop/java.awt.Robot.waitForIdle(Robot.java:757)
at org.sikuli.script.support.RobotDesktop.checkMousePosition(RobotDesktop.java:152)
at org.sikuli.script.support.RobotDesktop.smoothMove(RobotDesktop.java:141)
at org.sikuli.script.support.RobotDesktop.smoothMove(RobotDesktop.java:111)
at org.sikuli.script.Mouse.doMove(Mouse.java:317)
at org.sikuli.script.Mouse.move(Mouse.java:445)
at org.sikuli.script.Mouse.move(Mouse.java:390)
at org.sikuli.script.Screen.initScreens(Screen.java:164)
at org.sikuli.script.Screen.getNumberScreens(Screen.java:380)
at Main.click(Main.java:6212)
at Main.openVSProject(Main.java:6191)
at Main$93.actionPerformed(Main.java:3453)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1972)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2314)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:407)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
at java.desktop/java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:297)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6621)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3404)
at java.desktop/java.awt.Component.processEvent(Component.java:6386)
at java.desktop/java.awt.Container.processEvent(Container.java:2266)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4996)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4828)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4948)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4575)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4516)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2310)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2780)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4828)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:775)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:98)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:747)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:744)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Java:
import org.sikuli.script.*;
import javax.swing.SwingUtilities;
meineerstewebsite.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
openVSProject("Test");
} catch (InterruptedException ex) {
throw new RuntimeException(ex);
}
}
});
public static void openVSProject(String name) throws InterruptedException {
openVS();
System.out.println("VS wurde geöffnet!");
Thread.sleep(10000);
click("/res/VSPic/FileButton.JPG");
click("/res/VSPic/OpenFolderButton.JPG");
Thread.sleep(3000);
click("/res/VSPic/DocumentsButton.JPG");
click("/res/VSPic/PathInputButton.JPG");
input("C:xxxxx" + name);
click("/res/VSPic/OrdnerChooseButton.JPG");
}
public static void click(String Path) {
URL imagePath = Main.class.getResource(Path);
Pattern button = new Pattern(imagePath);
int numberOfScreens = Screen.getNumberScreens();
for (int i = 0; i < numberOfScreens; i++) {
Screen screen = new Screen(i);
System.out.println("Überprüfe Bildschirm: " + i);
try {
screen.wait(button, 5);
screen.click(button);
System.out.println("Button erfolgreich auf Bildschirm " + i + " angeklickt!");
return;
} catch (FindFailed e) {
System.out.println("Button nicht gefunden: " + e.getMessage());
}
}
}