NvServices
NvServices

Reputation: 227

Codenameone new GUI Builder null pointer when trying to assign image to button

When using the new GUI Builder (CN1 plugin v3.6.0) I can attach an image from my res file to a Button and it appears in the preview nicely button showing image from res file but when I try to run the code in the Simulator I get a NullPointerException on the line

  gui_ordersButton.setIcon(resourceObjectInstance.getImage("Orders.png"));

As this is in the magic "do not edit below this line" block how can I fix this?

Many thanks.

Upvotes: 1

Views: 51

Answers (1)

Shai Almog
Shai Almog

Reputation: 52760

Two elements can throw a null pointer from this exact line:

gui_ordersButton.setIcon(resourceObjectInstance.getImage("Orders.png"));

gui_ordersButton or resourceObjectInstance. If the image isn't available in the resources the null pointer will come from the setIcon method.

I'm guessing resourceObjectInstance is null because you changed something about the way resources are loaded in the default project or you used the constructor of the form that passes null as the resources object.

Upvotes: 1

Related Questions