← Back to team overview

sikuli-driver team mailing list archive

[Question #145455]: Error: Cannot call method from the event dispatcher thread

 

Question #145455 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/145455

Description changed to:
Hello!

I have a script running on a mac (osx 10.6), that finds some element
position in one game and then it should click on it. I am using swing
framework to make a form with a button, so that the script starts when I
press the button. The script code is:

from javax.swing import JFrame, JButton, JLabel
from java.awt.BorderLayout import NORTH

#Globals
fishing=0
pos=0
posbait=0

	
def React(event):
	global fishing
	if fishing==1:
		# first time: cast, findpos
		App.focus("---") 
		click(Location(568,778))
		global posbait
		posbait = Region(125,263,795,389).find(Pattern("1A.png").similar(0.68))
		if posbait!=0:
			popup("found")
		else:
			popup("not found")
		#global fishing
		#fishing=2
	else:
		# continue: cath, loot, cast, findpos
		popup("step 2")
		CatchBait()
		CastLure()
		FindBaitPos()
		

fishing=1
frame = JFrame("Rrr", size=(120,60))
frame.setLocation(1320,850)
button = JButton("push", actionPerformed=React)
label = JLabel("Created")
frame.add(button)
frame.add(label, NORTH)
frame.visible=True


-------
click(Location(568,778)) runs ok, but just after this line the script stops and the following log appears in the Message window:
...
...
[log] CLICK on (568,778) 
[debug] showTarget 528 738 80 80 
Exception in thread "AWT-EventQueue-0" java.lang.IllegalThreadStateException: Cannot call method from the event dispatcher thread  at java.awt.Robot.checkNotDispatchThread(Robot.java:465)  at java.awt.Robot.waitForIdle(Robot.java:444)  at org.sikuli.script.Region._click(Region.java:899)  at org.sikuli.script.Region.click(Region.java:489)  at org.python.proxies.sikuli.Region$Region$1.super__click(Unknown Source)  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  at java.lang.reflect.Method.invoke(Method.java:597)  at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:175)  at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)  at org.python.core.PyObject.__call__(PyObject.java:432)  at org.python.core.PyObject.__call__(PyObject.java:436)  at sikuli.Region$py.click$10(/Applications/Siku 
li-IDE.app/Contents/Resources/Java/sikuli-script.jar/Lib/sikuli/Region.py:119)  at sikuli.Region$py.call_function(/Applications/Sikuli-IDE.app/Contents/Resources/Java/sikuli-script.jar/Lib/sikuli/Region.py)  at org.python.core.PyTableCode.call(PyTableCode.java:165)  at org.python.core.PyBaseCode.call(PyBaseCode.java:297)  at org.python.core.PyBaseCode.call(PyBaseCode.java:191)  at org.python.core.PyFunction.__call__(PyFunction.java:385)  at org.python.core.PyMethod.__call__(PyMethod.java:215)  at org.python.core.PyMethod.instancemethod___call__(PyMethod.java:221)  at org.python.core.PyMethod.__call__(PyMethod.java:206)  at org.python.core.PyObject.__call__(PyObject.java:397)  at org.python.core.PyObject.__call__(PyObject.java:401)  at org.python.pycode._pyx152.React$1(/var/folders/4X/4XG5PdRVEBGnd8Lb5Bl2kU+++TI/-Tmp-/sikuli-tmp328779133023807328.py:29)  at org.python.pycode._pyx152.call_function(/var/folders/4X/4XG5PdRVEBGnd8Lb5Bl2kU+++TI/-Tmp-/sikuli-tmp328779133023807328.py)  at org.python.core.PyTableCode. 
call(PyTableCode.java:165)  at org.python.core.PyBaseCode.call(PyBaseCode.java:297)  at org.python.core.PyFunction.__call__(PyFunction.java:370)  at org.python.core.PyFunction.function___call__(PyFunction.java:375)  at org.python.core.PyFunction.__call__(PyFunction.java:365)  at org.python.core.PyCompoundCallable.__call__(PyCompoundCallable.java:26)  at org.python.core.PyObject.__call__(PyObject.java:367)  at org.python.core.PyObject._jcallexc(PyObject.java:3500)  at org.python.core.PyObject._jcall(PyObject.java:3532)  at org.python.proxies.java.awt.event.ActionListener.actionPerformed(Unknown Source)  at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)  at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)  at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)  at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)  at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)  at jav 
a.awt.Component.processMouseEvent(Component.java:6352)  at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)  at java.awt.Component.processEvent(Component.java:6117)  at java.awt.Container.processEvent(Container.java:2085)  at java.awt.Component.dispatchEventImpl(Component.java:4714)  at java.awt.Container.dispatchEventImpl(Container.java:2143)  at java.awt.Component.dispatchEvent(Component.java:4544)  at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4621)  at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4282)  at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4212)  at java.awt.Container.dispatchEventImpl(Container.java:2129)  at java.awt.Window.dispatchEventImpl(Window.java:2478)  at java.awt.Component.dispatchEvent(Component.java:4544)  at java.awt.EventQueue.dispatchEvent(EventQueue.java:635)  at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)  at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatch 
Thread.java:211)  at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)  at java.awt.EventDispatchThread.run(EventDispatchThread.java:122) 
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException  at org.sikuli.ide.SikuliPane.getFileInBundle(SikuliPane.java:572)  at org.sikuli.ide.SikuliPane.replaceWithImage(SikuliPane.java:681)  at org.sikuli.ide.SikuliPane.parseLine(SikuliPane.java:537)  at org.sikuli.ide.SikuliPane.paste(SikuliPane.java:356)  at javax.swing.text.DefaultEditorKit$PasteAction.actionPerformed(DefaultEditorKit.java:1342)  at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1639)  at javax.swing.JComponent.processKeyBinding(JComponent.java:2851)  at javax.swing.JComponent.processKeyBindings(JComponent.java:2886)  at javax.swing.JComponent.processKeyEvent(JComponent.java:2814)  at java.awt.Component.processEvent(Component.java:6129)  at java.awt.Container.processEvent(Container.java:2085)  at java.awt.Component.dispatchEventImpl(Component.java:4714)  at java.awt.Container.dispatchEventImpl(Container.java:2143)  at java.awt.Component.dispatchEvent(Component.java:4544)  at java.awt.KeyboardFocusManager.redispa 
tchEvent(KeyboardFocusManager.java:1850)  at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:712)  at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:990)  at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:855)  at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:676)  at java.awt.Component.dispatchEventImpl(Component.java:4586)  at java.awt.Container.dispatchEventImpl(Container.java:2143)  at java.awt.Window.dispatchEventImpl(Window.java:2478)  at java.awt.Component.dispatchEvent(Component.java:4544)  at java.awt.EventQueue.dispatchEvent(EventQueue.java:635)  at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)  at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)  at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)  at java.awt.EventDispatchThread.pumpEvents( 
EventDispatchThread.java:196)  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)  at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

What could be wrong?

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.