# Closing a Vision Window on Error in visionWindowOpened

**URL:** <https://forum.inductiveautomation.com/t/closing-a-vision-window-on-error-in-visionwindowopened/50567>\
**Category:** Ignition\
**Tags:** scripting, vision\
**Created:** [September 2, 2021, 6:34pm UTC](https://forum.inductiveautomation.com/t/closing-a-vision-window-on-error-in-visionwindowopened/50567 "2021-09-02T18:34:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![brownja667](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@brownja667](https://forum.inductiveautomation.com/u/brownja667)\
**Post date:** [September 2, 2021, 6:34pm UTC](https://forum.inductiveautomation.com/t/closing-a-vision-window-on-error-in-visionwindowopened/50567/1 "2021-09-02T18:34:43Z")

</div>

I have an instance where a Try:Catch is throwing an exception in my visionWindowOpened. In this case, I want to display a MessageBox for the operator and then close out the Window once they acknowledge the error.  
The message box piece works, but I cannot seem to close the window. I get a Java error when I try to close the window. I assume this is because the Window has not completed the Open at this point. Is there a way around this?

Example:  
system.gui.messageBox(“Please verify system is online.”,“System Unavailable.”)  
system.nav.closeWindow("{Window Name}")

Also tried system.nav.closeWindow(event.source)

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 2, 2021, 6:35pm UTC](https://forum.inductiveautomation.com/t/closing-a-vision-window-on-error-in-visionwindowopened/50567/2 "2021-09-02T18:35:52Z")

</div>

Can you post your complete script of your visionWindowOpened?

---

<div class="post-metadata">

**Author:** ![brownja667](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@brownja667](https://forum.inductiveautomation.com/u/brownja667)\
**Post date:** [September 2, 2021, 7:22pm UTC](https://forum.inductiveautomation.com/t/closing-a-vision-window-on-error-in-visionwindowopened/50567/3 "2021-09-02T19:22:25Z")

</div>

```auto
try:
if	system.gui.getParentWindow(event).getComponentForPath('Root Container.tblLocationCodes').data == None
system.gui.getParentWindow(event).getComponentForPath('Root Container').errorWindowsClose = False
except:
	system.gui.messageBox("Please verify system is online","System Unavailable.")
	system.nav.closeWindow("addLocationCode")
```

I am reaching the MessageBox as expected, but am getting a Java NullPointer error on the closeWindow. I pulled out all of the code except for the closeWindow command and got the same error.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 2, 2021, 7:28pm UTC](https://forum.inductiveautomation.com/t/closing-a-vision-window-on-error-in-visionwindowopened/50567/4 "2021-09-02T19:28:12Z")

</div>

Are you sure that is the exact spelling of your window name? What happens if you use this instead  
`system.nav.closeParentWindow(event)`

---

<div class="post-metadata">

**Author:** ![brownja667](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@brownja667](https://forum.inductiveautomation.com/u/brownja667)\
**Post date:** [September 3, 2021, 1:26pm UTC](https://forum.inductiveautomation.com/t/closing-a-vision-window-on-error-in-visionwindowopened/50567/5 "2021-09-03T13:26:33Z")

</div>

Using system.nav.closeParentWindow(event) yields the same java error.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 3, 2021, 1:39pm UTC](https://forum.inductiveautomation.com/t/closing-a-vision-window-on-error-in-visionwindowopened/50567/6 "2021-09-03T13:39:48Z")

</div>

Get the error again, click on “Details” in the error message box, and paste that here.

---

<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:** [September 3, 2021, 1:45pm UTC](https://forum.inductiveautomation.com/t/closing-a-vision-window-on-error-in-visionwindowopened/50567/7 "2021-09-03T13:45:17Z")

</div>

Please also show the lines that _open_ that popup window.

---

<div class="post-metadata">

**Author:** ![brownja667](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@brownja667](https://forum.inductiveautomation.com/u/brownja667)\
**Post date:** [September 3, 2021, 2:14pm UTC](https://forum.inductiveautomation.com/t/closing-a-vision-window-on-error-in-visionwindowopened/50567/8 "2021-09-03T14:14:45Z")

</div>

```auto
window = system.nav.openWindow('addLocationCode', {'parentPath':parentPath, 'componentName':componentName, 'agvSystemID': agvSystemID})
system.nav.centerWindow(window)
```

Error on Close:  
Traceback (most recent call last):  
File “event:actionPerformed”, line 11, in   
java.lang.NullPointerException: java.lang.NullPointerException

```
caused by NullPointerException

```

Ignition v8.1.7 (b2021060314)  
Java: Azul Systems, Inc. 11.0.11

I was able to get around this by setting a custom property and then checking for that property to change in the Root Container Script. It works, but seems like a lot of extra code.
