I have a Vision Barcode Component which displays data from a tag. Between parts, the tag is empty so the Barcode Component shows a red error which is ugly.
I'm using property change script to try to hide the ugly control:
if event.propertyName == "code": # Ensure we only trigger on text changes
barcode_value = event.source.code # Read the current barcode value
if barcode_value is None or barcode_value == "" or barcode_value == "0":
event.source.visible = False
else:
event.source.visible = True
But something seems to be generating an exception:
12:26:37.682 [AWT-EventQueue-0] ERROR Vision.Barcode - Caught unexpected exception while recalculating barcode size for string 'null'
java.lang.NullPointerException: null
It really seems like there should be a "hide if no data" checkbox on the Barcode Component. What is the proper way to use the Barcode Component 'between parts' when there is no barcode?
Typically a null pointer exception (NPE) is a bug. Consider contacting support with a replication example. This forum is not official support.
Also, please properly format your code, it makes it easier for others to read and it maintains proper whitespace, which is important for jython. You can edit your post by clicking the pencil icon on the bottom right. Wiki - how to post code on this forum.
Consider moving the tag binding to a custom property, then using an expression binding involving coalesce() to replace the temporary null with an empty string, or some other string default.
This seems like the correct solution that I should be using everywhere, but the Barcode Component does not seem to have Custom Properties if I am looking in the right place:
I created a Custom Property on the root container with an expression binding of coalesce({[default]Station30/Barcode}, "") and that fixed the exception.