简体   繁体   English

尝试将图像分配给按钮时,代号为新的 GUI 生成器空指针

[英]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使用新的 GUI 生成器(CN1 插件 v3.6.0)时,我可以将 res 文件中的图像附加到 Button 中,它会很好地显示在预览中按钮显示来自 res 文件的图像 but when I try to run the code in the Simulator I get a NullPointerException on the line但是当我尝试在模拟器中运行代码时,我在线上得到一个 NullPointerException

  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.非常感谢。

Two elements can throw a null pointer from this exact line:两个元素可以从这一行抛出一个空指针:

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

gui_ordersButton or resourceObjectInstance . gui_ordersButtonresourceObjectInstance If the image isn't available in the resources the null pointer will come from the setIcon method.如果图像在资源中不可用,则空指针将来自setIcon方法。

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.我猜resourceObjectInstance为 null,因为您更改了默认项目中资源加载方式的某些内容,或者您​​使用了将 null 作为资源对象传递的表单的构造函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM