0

我又是 Java 的新手。不能说我记得使用 ResourceBundle。我收到异常 Can't find resource for bundle 'ExceptionMessages_en_US',键。

这是我的 ListResourceBundle 类:

(我直接从 JavaDoc 中获取了示例,并用我自己的字符串对其进行了修改)

public class ExceptionMessages extends ListResourceBundle {

@Override
protected Object[][] getContents() {
     return new Object[][] {

             {"interfaceCount", "Device should have 1 interface."},
             {"epCount", "Device should have 3 endpoints."},
             {"noIntrIn", "Device does not have an interrupt input endpoint."},
             {"noBulkIn", "Device does not have a bulk input endpoint."},
             {"noBulkOut", "Device does not have a bulk output endpoint."},
             {"openFailed", "A call to deviceOpen has failed."},
             {"claimFailed", "A call to claimInterface has failed."},
             {"startSessionFailed", "Start USB Session has failed."},
             {"sessionNotStarted", "USB Session not started."},
             {"bulkTxError", "Bulk endpoint transmit error."},
             {"intrRxError", "Interrupt endpoint recieve error."},


        };  
}

}

我也尝试命名类 ExceptionMessages_en_US 没有运气

我得到这样的资源包:

public void Test()
{
    try
    {
        ResourceBundle rb = ResourceBundle.getBundle("ExceptionMessages");
    }
    catch (Exception e)
    {
        e.printStackTrace();


    }

    int i = 0;
    i++;


}

我也累了:

 public void Test()
 {
    try
    {
        ResourceBundle rb = ResourceBundle.getBundle("ExceptionMessages",new Locale("en", "US"));
    }
    catch (Exception e)
    {
        e.printStackTrace();


    }

    int i = 0;
    i++;


}

但仍然得到异常。

我错过了什么?我敢肯定这是愚蠢的。

4

1 回答 1

0

我需要添加包含 ExceptionMessages 的完整包。

例子:

        ResourceBundle rb = ResourceBundle.getBundle("com.mycomp.ExceptionMessages");
于 2013-04-20T07:06:40.740 回答