# IllegalStateException: No node currently selected - when program is loaded from file

**URL:** <https://forum.universal-robots.com/t/illegalstateexception-no-node-currently-selected-when-program-is-loaded-from-file/2509>\
**Category:** URCaps SDK\
**Created:** [August 13, 2018, 10:12am UTC](https://forum.universal-robots.com/t/illegalstateexception-no-node-currently-selected-when-program-is-loaded-from-file/2509 "2018-08-13T10:12:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon38923855](https://avatars.discourse-cdn.com/v4/letter/a/5e9695/32.png) [@anon38923855](https://forum.universal-robots.com/u/anon38923855)\
**Post date:** [August 13, 2018, 10:12am UTC](https://forum.universal-robots.com/t/illegalstateexception-no-node-currently-selected-when-program-is-loaded-from-file/2509/1 "2018-08-13T10:12:22Z")

</div>

Hello,  
I’m creating a new URCap and I’ve faced a problem, which seems to be in URCaps SDK. This problem is reproduciable with “Hello World Swing” sample from the sdk.

Steps to reproduce:

1. Download the SDK 1.3.55
2. Go to the `samples/swing` folder and install `helloworldswing` URCap on URSim 3.6. (To do this you can just specify `ursim.home` at project’s pom.xml and run `mvn install -P ursim`)
3. Run URSim, select Program Robot, Empty Program.
4. Go to the Installation tab, Hello World Swing and enter a Popup title.
5. Go to the Program tab, add Hello World Swing node to program.
6. Save program to file.
7. Close URSim.
8. Start URSim again.
9. Load the saved program.
10. Click on text input in Hello World Swing node’s interface.

You’ve got the following exception:

```auto
ERROR [AWT-EventQueue-0] 11:32:43 13/08/18: Caught an unhandled exception
java.lang.IllegalStateException: No node currently selected.
	at com.ur.urcap.contribution.program.SwingProgramNodeViewProviderImpl$1.get(SwingProgramNodeViewProviderImpl.java:99)
	at com.ur.urcap.examples.helloworldswing.impl.HelloWorldProgramNodeView$1.mousePressed(HelloWorldProgramNodeView.java:60)
	at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:280)
	at java.awt.Component.processMouseEvent(Component.java:6536)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
	at java.awt.Component.processEvent(Component.java:6304)
	at java.awt.Container.processEvent(Container.java:2239)
	at java.awt.Component.dispatchEventImpl(Component.java:4889)
	at java.awt.Container.dispatchEventImpl(Container.java:2297)
	at java.awt.Component.dispatchEvent(Component.java:4711)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4532)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
	at java.awt.Container.dispatchEventImpl(Container.java:2283)
	at java.awt.Window.dispatchEventImpl(Window.java:2746)
	at java.awt.Component.dispatchEvent(Component.java:4711)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
	at java.awt.EventQueue.access$500(EventQueue.java:97)
	at java.awt.EventQueue$3.run(EventQueue.java:709)

```

The exception is thrown then `provider.get()` is called.  
It seems to me, that there is a bug in SDK, because in debug I can see, that the reference to Contribution is null, but the node is selected:

 ![Bad](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/1X/954425b086e0ceeb8e44a142e581607c8e81136f.png)  
Proper working state, when there are no errors:  
 ![Good](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/1X/90ee04808ad7da575eb574d6d058ba2cdd3c3294.png)

As a workaround, you can implement `setContribution` in your View and call it in Contribution.openView method `view.setContribution(this)`. And in closeView - `view.setContribution(null)`.  
But it was expected to call `provider.get()` on ContributionProvider object and the example illustrates it.

Am I doing everything right?  
Is there a bug in the SDK?  
How can I fix it? Should I use the workaround I have described?

Related topics:

> [@IllegalStateException: No node currently selected - multiple program node types](https://forum.universal-robots.com/t/illegalstateexception-no-node-currently-selected-multiple-program-node-types/2400):
>
> I have been struggling with this exception in my own project, and I went to the trouble to create a reproducible test case starting with the Hello World Swing example. I wasn’t sure what was causing the issue, so I made a number of changes to the example. The key change seems to be adding a second program node type in my URCap. Once I did this, I could reliably generate an exception. I then modified my URCap structure to match the pickorplace example, since that has two program nodes. They…

> [@URCap works as a single Node but not as a Child Node](https://forum.universal-robots.com/t/urcap-works-as-a-single-node-but-not-as-a-child-node/2342):
>
> Hi, I am writing a Main-URCap that adds a Sub-URCap as a Child Node automatically when a button is pressed. When I add the Main-URCap to the Program Tree and press the button the Sub-URCap gets added but when I click on it to configure it I get an error screen saying: java.lang.IllegalStateException: No node currently selected. This is interesting as the Sub-URCap works fine on its own when inserted directly into the Program Tree. An…

---

<div class="post-metadata">

**Author:** ![andrew.kittross](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@andrew.kittross](https://forum.universal-robots.com/u/andrew.kittross)\
**Post date:** [August 13, 2018, 2:41pm UTC](https://forum.universal-robots.com/t/illegalstateexception-no-node-currently-selected-when-program-is-loaded-from-file/2509/2 "2018-08-13T14:41:43Z")

</div>

I have completely avoided this exception with the workaround suggested above. implement `setContribution` in your View and call it in Contribution.openView method `view.setContribution(this)` And in closeView - `view.setContribution(null)`. The setContribution method wraps a class member of the contribution node type, so you can use this for everything and don’t need to call provider.get() at all.

---

<div class="post-metadata">

**Author:** ![anon91082083](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@anon91082083](https://forum.universal-robots.com/u/anon91082083)\
**Post date:** [August 31, 2018, 3:48am UTC](https://forum.universal-robots.com/t/illegalstateexception-no-node-currently-selected-when-program-is-loaded-from-file/2509/3 "2018-08-31T03:48:30Z")

</div>

I am also having this issue. I have two program nodes. One of them allowsChildren(true) and the other (the child node) isUserInsertable(false). Everything seems to work fine until I try to focus on a textfield in the child node. Whenever I do this the error pops up. I have looked into solutions for this from the java swing end with not success.

---

<div class="post-metadata">

**Author:** ![anon12495347](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@anon12495347](https://forum.universal-robots.com/u/anon12495347)\
**Post date:** [September 11, 2018, 2:28pm UTC](https://forum.universal-robots.com/t/illegalstateexception-no-node-currently-selected-when-program-is-loaded-from-file/2509/4 "2018-09-11T14:28:50Z")

</div>

Did you now find any proper solution ? Thanks for your response.

---

<div class="post-metadata">

**Author:** ![anon12495347](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@anon12495347](https://forum.universal-robots.com/u/anon12495347)\
**Post date:** [September 12, 2018, 7:08am UTC](https://forum.universal-robots.com/t/illegalstateexception-no-node-currently-selected-when-program-is-loaded-from-file/2509/5 "2018-09-12T07:08:33Z")

</div>

The new version 3.7 solves the problem according to the release notes .
