java.util.MissingResourceException:找不到基本名称配置包,语言环境

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11932566/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 06:59:36  来源:igfitidea点击:

java.util.MissingResourceException: Can't find bundle for base name config, locale en

javaconfiguration-filesjdeveloperresourcebundle

提问by yetAnotherSE

I looked answers of this question but they did not work for me. I have a file called "config_en.properties" in the Resources folder. (Project->Resources->config_en.properties)

我查看了这个问题的答案,但它们对我不起作用。我在资源文件夹中有一个名为“config_en.properties”的文件。(项目->资源->config_en.properties)

jms_Address=t3://127.0.0.1:7101
connection_Lookup_Address=BatchApp-BatchGebelikTakip-BatchGebelikTakipEJB#tr.com.surat.esaglik.batch.ejb.IBatchGebelikTakipEJB

And in my java class I try to read this config:

在我的 java 类中,我尝试阅读此配置:

private static final String fileName="config"; 

public static final String jms_Address="jms_Address";
public static final String conn_Lookup_Address="connection_Lookup_Address";
private static ResourceBundle res;
private static ClassLoader cl;
static {
    try {
        cl = Thread.currentThread().getContextClassLoader();
        res = ResourceBundle.getBundle(fileName, Locale.ENGLISH, cl);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

public void test(){
    System.out.println(res.getString(jms_Address).
}

But I get this error messages:

但我收到此错误消息:

java.util.MissingResourceException: Can't find bundle for base name config, locale en
    at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1427)
    at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1250)
    at java.util.ResourceBundle.getBundle(ResourceBundle.java:952)
    at tr.com.surat.esaglik.batch.Main.<clinit>(Main.java:34)
java.lang.NullPointerException
    at tr.com.surat.esaglik.batch.Main.getInitialContext(Main.java:74)
    at tr.com.surat.esaglik.batch.Main.run(Main.java:43)

What is wrong?

怎么了?

enter image description here

在此处输入图片说明

回答by evg

I made a simple app that shows how to load resource bundle

我制作了一个简单的应用程序,展示了如何加载资源包

enter image description here

在此处输入图片说明

Main.java

主程序

package org.stackoverflow.main;

import java.util.Locale;
import java.util.ResourceBundle;

/**
 * @author Eugene Pavlovsky
 * @since 13.08.12
 */
public class Main {

  public static void main(String[] args) {
    ResourceBundle resourceBundle = ResourceBundle.getBundle("org.stackoverflow.config.config", Locale.ENGLISH);
    System.out.println(resourceBundle != null);
  }
}