# Null Pointer Exception/Error on Window Activated / Opened

**URL:** <https://forum.inductiveautomation.com/t/null-pointer-exception-error-on-window-activated-opened/33656>\
**Category:** Ignition\
**Tags:** ignition80, scripting, vision\
**Created:** [April 3, 2020, 7:26am UTC](https://forum.inductiveautomation.com/t/null-pointer-exception-error-on-window-activated-opened/33656 "2020-04-03T07:26:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![csanyia](https://avatars.discourse-cdn.com/v4/letter/c/48db29/32.png) [@csanyia](https://forum.inductiveautomation.com/u/csanyia)\
**Post date:** [April 3, 2020, 7:26am UTC](https://forum.inductiveautomation.com/t/null-pointer-exception-error-on-window-activated-opened/33656/1 "2020-04-03T07:26:22Z")

</div>

Using this code to load an image from BLOB in the database into the icon field of a label.  
When the code is attached to a button, it works fine, but I need the code to load the image as soon as the popup window is opened. I’m trying to add the code when the window is activated / opened, but get a null exception:

The Code in WindowActivated/WindowOpened

```auto
from javax.swing import ImageIcon
from java.io import ByteArrayInputStream
from javax.imageio import ImageIO
from java.awt import Image
from java.net import URL
from java.io import File
image = system.db.runScalarPrepQuery("SELECT image FROM Products where id=15757")
bais = ByteArrayInputStream(image)
bImageFromConvert = ImageIO.read(bais)
lbl3 = event.source.parent.getComponent('Label 29')
boundWidth = lbl3.width
boundHeight = lbl3.height
originalWidth = bImageFromConvert.width
originalHeight = bImageFromConvert.height
newWidth = originalWidth
newHeight = originalHeight
if originalWidth > boundWidth:
   newWidth = boundWidth
   newHeight = (newWidth * originalHeight) / originalWidth
if newHeight > boundHeight:
   newHeight = boundHeight
   newWidth = (newHeight * originalWidth) / originalHeight
scaledImage = bImageFromConvert.getScaledInstance(newWidth,newHeight,Image.SCALE_SMOOTH)
lbl3.setIcon(ImageIcon(scaledImage))

The Error in designer:

Traceback (most recent call last):
  File "<event:internalFrameOpened>", line 10, in <module>
	at org.python.core.PyJavaType.wrapJavaObject(PyJavaType.java:90)
	at com.inductiveautomation.factorypmi.application.script.PyComponentWrapper.<init>(PyComponentWrapper.java:57)
	at com.inductiveautomation.factorypmi.application.script.PyComponentWrapper. __findattr_ex__ (PyComponentWrapper.java:94)
	at org.python.core.PyObject. __getattr__ (PyObject.java:1025)
	at org.python.pycode._pyx29.f$0(<event:internalFrameOpened>:24)
	at org.python.pycode._pyx29.call_function(<event:internalFrameOpened>)
	at org.python.core.PyTableCode.call(PyTableCode.java:171)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1614)
	at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:770)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:200)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:291)
	at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:57)
	at com.sun.proxy.$Proxy60.internalFrameOpened(Unknown Source)
	at java.desktop/javax.swing.JInternalFrame.fireInternalFrameEvent(Unknown Source)
	at java.desktop/javax.swing.JInternalFrame.show(Unknown Source)
	at java.desktop/java.awt.Component.show(Unknown Source)
	at java.desktop/java.awt.Component.setVisible(Unknown Source)
	at java.desktop/javax.swing.JComponent.setVisible(Unknown Source)
	at com.inductiveautomation.factorypmi.designer.workspace.WindowWorkspace$DesigntimeWindowOpener.openWindow(WindowWorkspace.java:3514)
	at com.inductiveautomation.factorypmi.application.VisionDesktop.openWindow(VisionDesktop.java:197)
	at com.inductiveautomation.factorypmi.application.script.builtin.NavUtilities.lambda$openWindowImpl$5(NavUtilities.java:393)
	at com.inductiveautomation.factorypmi.application.script.builtin.WindowUtilities.doGUIAction(WindowUtilities.java:808)
	at com.inductiveautomation.factorypmi.application.script.builtin.NavUtilities.openWindowImpl(NavUtilities.java:336)
	at com.inductiveautomation.factorypmi.application.script.builtin.NavUtilities.openWindow(NavUtilities.java:326)
	at com.inductiveautomation.factorypmi.application.script.builtin.NavUtilitiesDispatcher.openWindow(NavUtilitiesDispatcher.java:143)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
java.lang.NullPointerException: java.lang.NullPointerException

	at org.python.core.Py.JavaError(Py.java:552)
	at org.python.core.PyTableCode.call(PyTableCode.java:180)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1614)
	at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:770)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:200)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:291)
	at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:57)
	at com.sun.proxy.$Proxy60.internalFrameOpened(Unknown Source)
	at java.desktop/javax.swing.JInternalFrame.fireInternalFrameEvent(Unknown Source)
	at java.desktop/javax.swing.JInternalFrame.show(Unknown Source)
	at java.desktop/java.awt.Component.show(Unknown Source)
	at java.desktop/java.awt.Component.setVisible(Unknown Source)
	at java.desktop/javax.swing.JComponent.setVisible(Unknown Source)
	at com.inductiveautomation.factorypmi.designer.workspace.WindowWorkspace$DesigntimeWindowOpener.openWindow(WindowWorkspace.java:3514)
	at com.inductiveautomation.factorypmi.application.VisionDesktop.openWindow(VisionDesktop.java:197)
	at com.inductiveautomation.factorypmi.application.script.builtin.NavUtilities.lambda$openWindowImpl$5(NavUtilities.java:393)
	at com.inductiveautomation.factorypmi.application.script.builtin.WindowUtilities.doGUIAction(WindowUtilities.java:808)
	at com.inductiveautomation.factorypmi.application.script.builtin.NavUtilities.openWindowImpl(NavUtilities.java:336)
	at com.inductiveautomation.factorypmi.application.script.builtin.NavUtilities.openWindow(NavUtilities.java:326)
	at com.inductiveautomation.factorypmi.application.script.builtin.NavUtilitiesDispatcher.openWindow(NavUtilitiesDispatcher.java:143)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:188)
	at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction. __call__ (ScriptManager.java:519)
	at org.python.core.PyObject. __call__ (PyObject.java:480)
	at org.python.core.PyObject. __call__ (PyObject.java:484)
	at org.python.pycode._pyx5.f$0(<event:actionPerformed>:7)
	at org.python.pycode._pyx5.call_function(<event:actionPerformed>)
	at org.python.core.PyTableCode.call(PyTableCode.java:171)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1614)
	at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:770)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:200)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:291)
	at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:57)
	at com.sun.proxy.$Proxy58.actionPerformed(Unknown Source)
	at java.desktop/javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at java.desktop/javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.desktop/java.awt.Component.processMouseEvent(Unknown Source)
	at java.desktop/javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.desktop/java.awt.Component.processEvent(Unknown Source)
	at java.desktop/java.awt.Container.processEvent(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEvent(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(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
	at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	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)
Caused by: java.lang.NullPointerException
	at org.python.core.PyJavaType.wrapJavaObject(PyJavaType.java:90)
	at com.inductiveautomation.factorypmi.application.script.PyComponentWrapper.<init>(PyComponentWrapper.java:57)
	at com.inductiveautomation.factorypmi.application.script.PyComponentWrapper. __findattr_ex__ (PyComponentWrapper.java:94)
	at org.python.core.PyObject. __getattr__ (PyObject.java:1025)
	at org.python.pycode._pyx29.f$0(<event:internalFrameOpened>:24)
	at org.python.pycode._pyx29.call_function(<event:internalFrameOpened>)
	at org.python.core.PyTableCode.call(PyTableCode.java:171)
	... 72 more

Ignition v8.0.8 (b2020021111)
Java: Azul Systems, Inc. 11.0.5

```

Error in vision:

```auto
Traceback (most recent call last):
  File "<event:internalFrameOpened>", line 10, in <module>
TypeError: getComponent(): 1st arg can't be coerced to int

Ignition v8.0.8 (b2020021111)
Java: Azul Systems, Inc. 11.0.5

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 3, 2020, 11:45am UTC](https://forum.inductiveautomation.com/t/null-pointer-exception-error-on-window-activated-opened/33656/2 "2020-04-03T11:45:42Z")

</div>

`event.source` in a window event is the window. In your button events it is the button. You’ll need something like:

```auto
lbl3 = event.source.rootContainer.getComponent('Label 29')

```

Note: please edit your post to properly delimit your pasted code and exception text. Use three backticks together above and below the pasted material so it formats properly. It should look like this in the forum’s editor pane:  
```  
pasted material  
```

---

<div class="post-metadata">

**Author:** ![csanyia](https://avatars.discourse-cdn.com/v4/letter/c/48db29/32.png) [@csanyia](https://forum.inductiveautomation.com/u/csanyia)\
**Post date:** [April 3, 2020, 3:14pm UTC](https://forum.inductiveautomation.com/t/null-pointer-exception-error-on-window-activated-opened/33656/3 "2020-04-03T15:14:57Z")

</div>

Seems so obvious now, worked like a charm. Thanks! I also edited my original post, to have proper formatting.

Thanks again.
