[英]Can't find resource bundle exception
I want to use a resource bundle called strings
but I get following error when running my main method in MainApplication.java
:我想使用名为
strings
的资源包,但在MainApplication.java
运行我的 main 方法时出现以下错误:
java.util.MissingResourceException: Can't find bundle for base name strings, locale de_DE
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1564)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1387)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:845)
at logic.MainApplication.start(MainApplication.java:20) (...)
My project structure:我的项目结构:
The two files strings.properties
and strings_de_DE.properties
are stored in the same directory as MainApplication.java
and all three files are in the directory pi_display/src/logic/
(IntelliJ puts them into a virtual "Resource Bundle" directory for a clearer display of the project structure).两个文件
strings.properties
和strings_de_DE.properties
被存储在同一个目录中MainApplication.java
和所有三个文件在目录pi_display/src/logic/
(的IntelliJ将其放入用于更清晰的显示一个虚拟的“资源束”目录项目结构)。
Main class/method:主要类/方法:
public class MainApplication {
public static void main(String[] args) {
Locale locale = Locale.GERMANY;
ResourceBundle resources = ResourceBundle.getBundle("strings", locale);
// ...
}
I've already tried to move the files to other packages and specify the baseName
of the bundle (ie logic.strings
or other package structures if I moved them elsewhere).我已经尝试将文件移动到其他包并指定包的
baseName
(即,如果我将它们移动到其他地方, logic.strings
或其他包结构)。
I don't understand why the bundle can't be found given MainApplication
and the bundle files are in the same directory.我不明白为什么在给定
MainApplication
下找不到MainApplication
,并且包文件在同一目录中。
You probably using wrong baseName
for your bundle.您可能为您的包使用了错误的
baseName
。 According to documentation :根据文档:
Gets a resource bundle using the specified base name, the default locale, and the caller's class loader
使用指定的基本名称、默认语言环境和调用者的类加载器获取资源包
"Class loader" means that resource loaded from folder with compiled classes. “类加载器”是指从带有编译类的文件夹加载的资源。 In the screenshot, the path to your resource is
src/logic/strings.properties
, so it should be located in classes/logic/
folder, and as baseName you should use logic/strings
(or logic/strings.properties
, I'm not sure about that).在屏幕截图中,资源的路径是
src/logic/strings.properties
,所以它应该位于classes/logic/
文件夹中,并且作为 baseName 你应该使用logic/strings
(或logic/strings.properties
,我是不确定)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.