在Android中找不到捆绑包'ExceptionMessages_en_US'的资源

时间:2013-04-19 01:48:14

标签: java android

我又是Java的新人。不能说我记得使用过ResourceBundle。我收到异常无法找到包'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++;


}

但仍然有例外。

我错过了什么?我确信这是愚蠢的。

1 个答案:

答案 0 :(得分:0)

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

示例:

        ResourceBundle rb = ResourceBundle.getBundle("com.mycomp.ExceptionMessages");