简体   繁体   English

找不到资源包异常

[英]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.propertiesstrings_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.

相关问题 找不到资源包 - Can't find resource bundle 发布时找不到资源束 - Can't find Resource Bundle at release time 无法找到bundle java.util的资源 - Can't find resource for bundle java.util 找不到包java.util.PropertyResourceBundle枚举的资源 - Can't find resource for bundle java.util.PropertyResourceBundle ENUM 在Glassfish部署期间无法找到捆绑资源 - Can't find resource for bundle during Glassfish deployment 找不到包java.util.PropertyResourceBundle的资源 - Can't find resource for bundle java.util.PropertyResourceBundle java.util.MissingResourceException:找不到捆绑包的资源 - java.util.MissingResourceException: Can't find resource for bundle 尝试将 a.properties 文件加载到资源包中时出现错误“找不到基本名称的包” - Trying to load a .properties file into Resource bundle getting error "Can't find bundle for base name" 为什么会发生此异常:“ java.util.MissingResourceException:找不到包java.util.PropertyResourceBundle,密钥MQJE001b的资源”? - Why does this exception occur: “java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key MQJE001b”? java.util.MissingResourceException:找不到捆绑包java.util.PropertyResourceBundle的资源 - java.util.MissingResourceException :Can't find resource for bundle java.util.PropertyResourceBundle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM