Java cast Error in Scripting

Help this script throws an error when I enter the data CLE-158 but then does what I want. I can't see what is causing a casting error as the tag ToolID is a string.

print "before the read"
temp_tool_ID = system.tag.readBlocking(["[client]Build/TaskData/ToolID.Value"])[0].value
print "read toolID"
print temp_tool_ID
temp_tool_ID2 = temp_tool_ID.strip()
print "stripped ID"
print temp_tool_ID2
tool_ID_num = temp_tool_ID2[-3:]
print "last 3"
print tool_ID_num
17:29:09.103 [AWT-EventQueue-0] ERROR c.i.i.client.util.gui.ErrorUtil - null
java.lang.ClassCastException: Error trying to coerce 'cle-158' to a number.
	at com.inductiveautomation.ignition.common.TypeUtilities.toNumber(TypeUtilities.java:838)
	at com.inductiveautomation.ignition.common.TypeUtilities.coerce(TypeUtilities.java:1256)
	at com.inductiveautomation.ignition.common.TypeUtilities.toInteger(TypeUtilities.java:1771)
	at com.inductiveautomation.ignition.common.TypeUtilities.coerce(TypeUtilities.java:1249)
	at com.inductiveautomation.factorypmi.application.binding.AbstractPropertyAdapter.setQValue(AbstractPropertyAdapter.java:223)
	at com.inductiveautomation.factorypmi.application.binding.AbstractPropertyAdapter.updateValue(AbstractPropertyAdapter.java:269)
	at com.inductiveautomation.factorypmi.application.binding.ExpressionPropertyAdapter.runExpression(ExpressionPropertyAdapter.java:89)
	at com.inductiveautomation.factorypmi.application.binding.ExpressionPropertyAdapter$1.run(ExpressionPropertyAdapter.java:59)
	at com.inductiveautomation.ignition.client.util.EDTUtil$ProcessQueue.run(EDTUtil.java:126)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
	at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Unknown Source)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)
before the read
read toolID
CLE-158  
stripped ID
CLE-158
last 3
158
before the read
read toolID
CLE-158  
stripped ID
CLE-158
last 3
158

That error appear to be happening outside your script. Show what else you have going on.

1 Like
	at com.inductiveautomation.ignition.common.TypeUtilities.toNumber(TypeUtilities.java:838)
	at com.inductiveautomation.ignition.common.TypeUtilities.coerce(TypeUtilities.java:1256)
	at com.inductiveautomation.ignition.common.TypeUtilities.toInteger(TypeUtilities.java:1771)
	at com.inductiveautomation.ignition.common.TypeUtilities.coerce(TypeUtilities.java:1249)
	at com.inductiveautomation.factorypmi.application.binding.AbstractPropertyAdapter.setQValue(AbstractPropertyAdapter.java:223)
	at com.inductiveautomation.factorypmi.application.binding.AbstractPropertyAdapter.updateValue(AbstractPropertyAdapter.java:269)
	at com.inductiveautomation.factorypmi.application.binding.ExpressionPropertyAdapter.runExpression(ExpressionPropertyAdapter.java:89)
	at com.inductiveautomation.factorypmi.application.binding.ExpressionPropertyAdapter$1.run(ExpressionPropertyAdapter.java:59)

Your script is not implicated.

You've got a property of an integer type, and you've got an expression running that's returning your cle-158 string value. That value cannot be turned into an integer implicitly by the expression, so it's failing.

1 Like