简体   繁体   English

netbeans和Java,resourceMap.getString返回null

[英]netbeans & java, resourceMap.getString returning null

Product Version: NetBeans IDE 6.8 (Build 200912041610) Java: 1.6.0_17; 产品版本:NetBeans IDE 6.8(Build 200912041610)Java:1.6.0_17; Java HotSpot(TM) Client VM 14.3-b01 System: Windows 7 version 6.1 running on x86; Java HotSpot(TM)客户端VM 14.3-b01系统:在x86上运行的Windows 7版本6.1; Cp1252; CP1252; en_GB (nb) en_GB(nb)

Hello, newbee java programmer here and wondering if someone can help, I have been having some problems updating a GUI for a desktop application in netbeans, here are the details: 您好,这里的newbee java程序员想知道是否有人可以提供帮助,我在为netbeans中的桌面应用程序更新GUI时遇到了一些问题,以下是详细信息:


my current application GUI works great, everything is appearing correctly. 我当前的应用程序GUI效果很好,一切都正确显示。

when I update the GUI by adding a new label from the netbeans toolbox onto my form, and use the netbeans preview function, everything looks great 当我通过将netbeans工具箱中的新标签添加到表单上来更新GUI并使用netbeans预览功能时,一切看起来都很棒

however when i run the application the new label has disappeared.. 但是,当我运行该应用程序时,新标签消失了。

to try and understand the problem i ran the app in debug mode and stepped through the auto-generated initComponents() code 尝试了解问题,我以调试模式运行了该应用程序,并逐步执行了自动生成的initComponents()代码

from debugging i believe the problem comes from this line of code: 通过调试,我相信问题来自以下代码行:

TEST_lbl.setText(resourceMap.getString("TEST_lbl.text")); // NOI18N

after this line of code has executed TEST_lbl.setText is equal to null.. 在此代码行执行之后,TEST_lbl.setText等于null。

so the label is disappearing when i run the app because it has no text value to display... 所以当我运行该应用程序时,该标签消失了,因为它没有文本值可显示...

i opened the resource map file in notepad (the .properties file) and it contains an entry "TEST_lbl.text=jLabel1" among the entries for all the other working controls... 我在记事本(.properties文件)中打开了资源映射文件,它在所有其他工作控件的条目中包含条目“ TEST_lbl.text = jLabel1” ...

so the properties file has the correct value, but resourceMap.getString is not retrieving it 因此属性文件具有正确的值,但是resourceMap.getString没有检索到它

i can work around this problem by changing the "Automatic Resource Management" option of the form from "All Resources" to "Off" 我可以通过将表格的“自动资源管理”选项从“所有资源”更改为“关”来解决此问题。

as a result this changes the auto-generated "setText" code line to: 结果,这会将自动生成的“ setText”代码行更改为:

TEST_lbl.setText("jLabel1"); 

and makes the label display correctly when the application runs 并在应用程序运行时使标签正确显示


my first question would be, is this a known bug? 我的第一个问题是,这是一个已知的错误吗? or have i done something silly and accidently changed a setting someware? 还是我做了一些愚蠢的事情,不小心更改了设置软件?

if this is not a bug, how do i correct the problem without changing the resource management setting? 如果这不是错误,如何在不更改资源管理设置的情况下解决问题?

if this is a bug, what are the implications of turning off automatic resource management? 如果这是一个错误,关闭自动资源管理的含义是什么?

Thanks for the help, - Gaz 感谢您的帮助-Gaz

I assume you're running it under NB (Run > Run Main Project)? 我假设您正在NB(运行>运行主项目)下运行它?

Try a clean build (Run > Clean and Build Main Project). 尝试进行干净的构建(运行>清理并构建主项目)。 That will usually fix it. 通常可以解决该问题。

It's an issue of how the build system is structured. 这是构建系统的结构问题。

When you run the project in a clean repository (Run > Run Main Project): 在干净的存储库中运行项目时(运行>运行主项目):

  1. the .class files are written to $project/build/classes .class文件被写入$ project / build / classes
  2. the non-class files are copied into the tree 非类文件被复制到树中
  3. the whole thing is run from there. 整个事情都是从那里开始的。

That works fine. 很好

If you "build" the project (Run > Build Main Project): 1. the .class files are written to $project/build/classes 2. the non-class files are copied into the tree 3. the whole thing rolled up into a jar file. 如果您“构建”项目(运行>构建主项目):1.将.class文件写入$ project / build / classes 2.将非类文件复制到树中3.将整个内容汇总到一个jar文件。

That also works fine. 那也很好。

However, if you subsequently make changes and run the project, the class files and resources now appear in 2 places: 但是,如果您随后进行更改并运行项目,则类文件和资源现在显示在两个位置:

  • in build/classes 在构建/类中
  • in the dist/ project .jar 在dist / 项目 .jar中

This works OK as far as finding class files. 就查找类文件而言,这样做行得通。 Resources, however, are found in the jar first. 但是,资源首先在jar中找到。 So, at runtime, you code finds the outdated copy of the properties file in the jar, not the new one in the filesystem. 因此,在运行时,您的代码会在jar中找到属性文件的过时副本,而不是文件系统中的新副本。

Also: NB ignores case when finding a resource, but Sun's JVM does not (not sure about IcedTea). 另外:NB在查找资源时会忽略大小写,但是Sun的JVM不会(不确定IcedTea)。 So, if the wrong case is used NB may insist the file is there, but the JVM will not be able to find it. 因此,如果使用了错误的情况,则NB可能会坚持认为文件存在,但JVM将无法找到它。

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

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