网豆java,resourceMap.getString 返回 null [英] netbeans & java, resourceMap.getString returning null

查看:64
本文介绍了网豆java,resourceMap.getString 返回 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

产品版本:NetBeans IDE 6.8(内部版本 200912041610)Java:1.6.0_17;Java HotSpot(TM) 客户端 VM 14.3-b01系统:运行在x86上的Windows 7 6.1版;cp1252;en_GB (nb)

Product Version: 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; Cp1252; en_GB (nb)

你好,这里的 newbee Java 程序员,想知道是否有人可以提供帮助,我在为 netbeans 中的桌面应用程序更新 GUI 时遇到了一些问题,以下是详细信息:

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:

我当前的应用程序 GUI 运行良好,一切正常.

my current application GUI works great, everything is appearing correctly.

当我通过将 netbeans 工具箱中的新标签添加到我的表单来更新 GUI 并使用 netbeans 预览功能时,一切看起来都很棒

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

然而,当我运行应用程序时,新标签消失了..

however when i run the application the new label has disappeared..

为了尝试理解问题,我在调试模式下运行应用程序并逐步执行自动生成的 initComponents() 代码

to try and understand the problem i ran the app in debug mode and stepped through the auto-generated initComponents() code

从调试我相信问题来自这行代码:

from debugging i believe the problem comes from this line of code:

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

这行代码执行完后TEST_lbl.setText等于null..

after this line of code has executed TEST_lbl.setText is equal to null..

所以当我运行应用程序时,标签消失了,因为它没有要显示的文本值...

so the label is disappearing when i run the app because it has no text value to display...

我在记事本中打开了资源映射文件(.properties 文件),它在所有其他工作控件的条目中包含一个条目TEST_lbl.text=jLabel1"...

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...

因此属性文件具有正确的值,但 resourceMap.getString 未检索它

so the properties file has the correct value, but resourceMap.getString is not retrieving it

我可以通过将表单的自动资源管理"选项从所有资源"更改为关闭"来解决此问题

i can work around this problem by changing the "Automatic Resource Management" option of the form from "All Resources" to "Off"

因此,这会将自动生成的setText"代码行更改为:

as a result this changes the auto-generated "setText" code line to:

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?

感谢您的帮助,-Gaz

Thanks for the help, - Gaz

推荐答案

我假设您在 NB(运行 > 运行主项目)下运行它?

I assume you're running it under NB (Run > Run Main Project)?

尝试清理构建(运行 > 清理并构建主项目).这通常会解决它.

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. .class 文件被写入 $project/build/classes
  2. 将非类文件复制到树中
  3. 整个过程都是从那里开始的.

效果很好.

如果您构建"项目(运行 > 构建主项目):1. .class 文件写入 $project/build/classes2.将非类文件复制到树中3. 整个东西卷成一个jar文件.

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.

这也很好用.

但是,如果您随后进行更改并运行该项目,类文件和资源现在会出现在 2 个位置:

However, if you subsequently make changes and run the project, the class files and resources now appear in 2 places:

  • 在构建/类中
  • 在 dist/project.jar

就查找类文件而言,这可以正常工作.但是,资源首先在 jar 中找到.因此,在运行时,您的代码会在 jar 中找到属性文件的过时副本,而不是文件系统中的新副本.

This works OK as far as finding class files. Resources, however, are found in the jar first. So, at runtime, you code finds the outdated copy of the properties file in the jar, not the new one in the filesystem.

另外:NB 在查找资源时会忽略大小写,但 Sun 的 JVM 不会(不确定 IcedTea).因此,如果使用错误的大小写,NB 可能会坚持文件在那里,但 JVM 将无法找到它.

Also: NB ignores case when finding a resource, but Sun's JVM does not (not sure about 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.

这篇关于网豆java,resourceMap.getString 返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆