Error message on startup script

Here is an error message I am receiving from my startup script. The thing is this does not occur every time. If I start the project in runtime say 10 times at least 3 will have this error message where the other 7 will be fine.

[quote]Traceback (innermost last):
File “”, line 25, in ?
java.lang.ClassCastException: Error trying to coerce ‘Fair’ to a class java.lang.Integer

at com.inductiveautomation.factorypmi.common.utils.TypeUtilities.coerce(TypeUtilities.java:511)

at com.inductiveautomation.factorypmi.application.sqltags.db.TagFacade.setAttribute(TagFacade.java:117)

at com.inductiveautomation.factorypmi.application.script.builtin.TagUtilities.writeToTag(TagUtilities.java:80)

at com.inductiveautomation.factorypmi.application.script.builtin.TagUtilities.writeToTag(TagUtilities.java:59)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)

at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)

at org.python.core.PyObject.__call__(PyObject.java)

at org.python.core.PyObject.invoke(PyObject.java)

at org.python.pycode._pyx0.f$0(<startup script>:25)

at org.python.pycode._pyx0.call_function(<startup script>)

at org.python.core.PyTableCode.call(PyTableCode.java)

at org.python.core.PyCode.call(PyCode.java)

at org.python.core.Py.runCode(Py.java)

at com.inductiveautomation.factorypmi.application.script.ScriptManager.runCode(ScriptManager.java:245)

at com.inductiveautomation.factorypmi.application.script.ScriptManager.runCode(ScriptManager.java:238)

at com.inductiveautomation.factorypmi.application.FPMIApp.startup(FPMIApp.java:672)

at com.inductiveautomation.factorypmi.application.runtime.RuntimePanel.initFPMIApp(RuntimePanel.java:626)

at com.inductiveautomation.factorypmi.application.runtime.RuntimePanel$LoginAction.doLogin(RuntimePanel.java:996)

at com.inductiveautomation.factorypmi.application.runtime.RuntimePanel$LoginAction.tryLoadApp(RuntimePanel.java:1041)

at com.inductiveautomation.factorypmi.application.runtime.RuntimePanel$LoginAction.access$300(RuntimePanel.java:942)

at com.inductiveautomation.factorypmi.application.runtime.RuntimePanel$LoginAction$LoginLockWaiter$1.run(RuntimePanel.java:963)

at java.awt.event.InvocationEvent.dispatch(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.ClassCastException: java.lang.ClassCastException: Error trying to coerce ‘Fair’ to a class java.lang.Integer

at org.python.core.Py.JavaError(Py.java)
at org.python.core.Py.JavaError(Py.java)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)
at org.python.core.PyObject.__call__(PyObject.java)
at org.python.core.PyObject.invoke(PyObject.java)
at org.python.pycode._pyx0.f$0(<startup script>:25)
at org.python.pycode._pyx0.call_function(<startup script>)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyCode.call(PyCode.java)
at org.python.core.Py.runCode(Py.java)
at com.inductiveautomation.factorypmi.application.script.ScriptManager.runCode(ScriptManager.java:245)
at com.inductiveautomation.factorypmi.application.script.ScriptManager.runCode(ScriptManager.java:238)
at com.inductiveautomation.factorypmi.application.FPMIApp.startup(FPMIApp.java:672)
at com.inductiveautomation.factorypmi.application.runtime.RuntimePanel.initFPMIApp(RuntimePanel.java:626)
at com.inductiveautomation.factorypmi.application.runtime.RuntimePanel$LoginAction.doLogin(RuntimePanel.java:996)
at com.inductiveautomation.factorypmi.application.runtime.RuntimePanel$LoginAction.tryLoadApp(RuntimePanel.java:1041)
at com.inductiveautomation.factorypmi.application.runtime.RuntimePanel$LoginAction.access$300(RuntimePanel.java:942)
at com.inductiveautomation.factorypmi.application.runtime.RuntimePanel$LoginAction$LoginLockWaiter$1.run(RuntimePanel.java:963)
at java.awt.event.InvocationEvent.dispatch(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)

[/quote]

Here is the code that is being ran that causes this error message.

val = fpmi.net.getIpAddress()
if val[0:2]=='10':
	fpmi.gui.openWindow("Window 1")

else:
	import fpmi
	import re
	fpmi.gui.openWindow("Window 1L")
	
	response = fpmi.net.httpGet("http://xml.weather.yahoo.com/forecastrss?p=17815")

# import Python's regular expression library
#	import re		

# NOTE - if you've never seen regular expressions before, don't worry, they look
# confusing even to people who use them frequently.
	pattern = re.compile('.*?<yweather:condition (.*?)/>', re.DOTALL)
	match = pattern.match(response)
	if match:
		subText = match.group(1)
		condition = re.compile('.*?text="(.*?)"').match(subText).group(1)
		temp = re.compile('.*?temp="(.*?)"').match(subText).group(1)
		fpmi.tag.writeToTag("[]temp",toint(temp))
		fpmi.tag.writeToTag("[]condition",str(condition))

	else:
		print 'Weather service format changed'

I have triedit with both toint and str. When I tried it with str the tag that I wrote to was a string, when I try it with the toint the tag is set as an int. So I dont think there is an issue but since I am getting the error message there must be something.

Well, I think the error message is pretty clear.

File "<startup script>", line 25, in ? java.lang.ClassCastException: Error trying to coerce 'Fair' to a class java.lang.Integer
Looks like you’re tring to coerce the string “Fair” to an integer on line 25. Thats not going to work so well.

Note that even though you’re casting the condition to a string using str(), if the type of the []condition tag is an int, it’ll get coerced to an integer when you set the value of the tag.