ResourceBundle problem

Hi;

If I call ResourceBundle.getBundle("resources", locale) where locale is for a locale I don't have a resource for (I used "zz_XX") - it throws the ArgumentOutOfRange exception.

In this case it should work and just use resources.properties.

I also tried "en_XX" which should fall back to resources_en.properties - but again I got the exception.

- dave


Answer this question

ResourceBundle problem

  • Paulme

    Hi,

    I am not getting the exception that you have mentioned. It would be really helpful if you could provide me your sample code and the resource files.

    The exception mentioned above is seen when neither of the following steps are done:
    1. Execute "resgen" on .resx format if you are working from commandline
    2. Add the .resx file to your project using the Visual Studio IDE.

    Thanking you in advance for your response.

    Regards,
    Ritesh.

  • John Seal

    Hi;

    Please try calling the following code for a resource you have. Change "resources" to the name of your resources.

    ResourceBundle.getBundle("resources", new Locale("xx", "zz"));

    thanks - dave

  • RPT

    Hi;

    Please ask the concerned person to email me. I can send them a program and they can just run it and it will cause this problem. I can also give them the source to the place where the problem happens.

    I just spent another hour trying to make a test program to do this - but it works. And I made it identical to what my program does, different DLLs, package names, directory structure - everything.

    thanks - dave

  • Edimilson Simionato

    Hi;

    I'm trying but each sample I create works - yet in my application it fails. I am using the same resources and file structure in both. Anything else you can think of

    I can also send you my entire program and if you run it, it will throw the exception. If you want that email me your email address. I am david@windward.net.

    thanks - dave

  • Dhakshna

    Hi;

    I'm begging again, what can I do to figure out what is wrong here

    thanks - dave

  • dtsob75

    Hi;

    Here is what I am doing (it's a bit different):
    vjsresgen /out:jsResources.resx *.properties
    add jsResources.resx to project
    build using VS 2005

    In my code:

    Object obj = ResourceBundle.getBundle("resources"); // works

    obj = ResourceBundle.getBundle("resources", new Locale("en", "us")); // works

    obj = ResourceBundle.getBundle("resources", new Locale("en", "xx")); // exception

    Any ideas When I pass a locale I have resources for, I get the strings back.

    thanks - dave



  • Ederaldo Mirandola

    Hi Dave,

    I am not very sure if I can use my email ID on public forums. It could be a violation of our forum guidelines. I have passed on the details to the concerned person, who will get in touch with you regarding this issue.

    Thanks,
    Ritesh.



  • Jan-Erik Sandberg

    Hi Dave,

    Below is the scenario that's been worked on:

    All the following files are in a single directory:
    appl.jsl -- This is the source file.
    MyresourceBundle.jsl -- This contains the class MyresourceBundle. This has 
    key as today and its value as Sunday
    MyresourceBundle.properties -- Content of this file is today=Monday
    MyresourceBundle_ja.properties -- Content of this file is today=Japan_Monday

    Code for appl.jsl
    import java.util.*;
    import java.io.*;
     
    public class appl
    {
     ClassLoader cloader;
     public static void main(String[] args) throws Exception
     {
      ResourceBundle rb;
      rb = ResourceBundle.getBundle("MyresourceBundle"); 
      System.out.println("for MyresourceBundle");
      System.out.println(rb.getClass());
      System.out.println(rb.getObject("today"));
      System.out.println("---------------------------");

      rb = ResourceBundle.getBundle("MyresourceBundle",Locale.FRENCH);
      System.out.println("for MyresourceBundle, locale french");
      System.out.println(rb.getClass());
      System.out.println(rb.getObject("today"));
      System.out.println("---------------------------");

      rb = ResourceBundle.getBundle("MyresourceBundle", Locale.JAPAN);
      System.out.println("for MyresourceBundle,locale japan");
      System.out.println(rb.getClass());
      System.out.println(rb.getObject("today"));
      System.out.println("---------------------------");

      rb = ResourceBundle.getBundle("MyresourceBundle_ja");
      System.out.println("for MyresourceBundle_ja");
      System.out.println(rb.getClass());
      System.out.println(rb.getObject("today"));
      System.out.println("---------------------------");

      rb = ResourceBundle.getBundle("MyresourceBundle",new Locale("fr","zz"));
      System.out.println("for MyresourceBundle, fr, zz");
      System.out.println(rb.getClass());
      System.out.println(rb.getObject("today"));
      System.out.println("---------------------------");

      rb = ResourceBundle.getBundle("MyresourceBundle",new Locale("xx","zz"));
      System.out.println("for MyresourceBundle, xx, zz");  
      System.out.println(rb.getClass());
      System.out.println(rb.getObject("today"));
      System.out.println("---------------------------");

       }
    }

    Commands executed:
    vjsresgen.exe /out:Myresource.resx  MyresourceBundle.properties MyresourceBundle_ja.properties
    resgen.exe Myresource.resx
    vjc.exe /res:Myresource.resources *.jsl

    Output:
    for MyresourceBundle
    class MyresourceBundle            ---------- this is the default output.
    Sunday
    ---------------------------
    for MyresourceBundle, locale french
    class MyresourceBundle           ---------- there is no french resource file and hence the Sunday                                               default output.
    ---------------------------
    for MyresourceBundle,locale japan
    class java.util.PropertyResourceBundle      ---------- there is a JA locale properties file
    Japan_Monday                                                    and hence its output.
    ---------------------------
    for MyresourceBundle_ja
    class java.util.PropertyResourceBundle     ---------- there is a JA locale properties file
    Japan_Monday                                                   and hence its output.
    ---------------------------
    for MyresourceBundle, fr, zz     ---------- there is no french resource file and hence the         
    class MyresourceBundle                     default output
    Sunday
    ---------------------------
    for MyresourceBundle, xx, zz  -------- there is no locale file for "xx" and "zz" locale and hence
    class MyresourceBundle                  the deault output.
    Sunday
    ---------------------------

    If any scenario has been missed, do let us know.

    Thanks,
    Regards,
    Ritesh.


  • Bart_p

    Hi Dave,

    Can you provide more information regarding your application.
    What resources are you using
    How are you using them

    I would really appreciate if you could provide us some sample code to work with.

    Thanks,
    Ritesh.

  • Matthew_Zeng

    Hi Dave,

    This is what i have tried:
    In one directory i have the following .properties files:
    1. MyresourceBundle.properties -- content is today=Monday
    2. MyresourceBundle_ja.properties -- content is today=Japan_Monday

    I executed the following command:
    vjsresgen /out:jsResources.resx *.properties
    I have then added jsResources.resx to the project.

    There are several scenarios that i have covered here. Last four scenarios are of interest. Second last scenario is identical to what you have reported.
    Its working fine for me.

    The source code is:
    import java.util.*;
    import java.io.*;
     
    public class appl
    {
     ClassLoader cloader;
     public static void main(String[] args) throws Exception
     {
      ResourceBundle rb;
      
    rb = ResourceBundle.getBundle("MyresourceBundle", Locale.JAPAN);
      System.out.println("for MyresourceBundle,locale japan");
      System.out.println(rb.getClass());
      System.out.println(rb.getObject("today"));
      System.out.println("---------------------------");

      rb = ResourceBundle.getBundle("MyresourceBundle_ja");
      System.out.println("for MyresourceBundle_ja");
      System.out.println(rb.getClass());
      System.out.println(rb.getObject("today"));
      System.out.println("---------------------------");
      
     rb = ResourceBundle.getBundle("MyresourceBundle",Locale.FRENCH);
      System.out.println("for MyresourceBundle, locale french");
      System.out.println(rb.getClass());
      System.out.println(rb.getObject("today"));
      System.out.println("---------------------------");

    rb = ResourceBundle.getBundle("MyresourceBundle",new Locale("ja","zz"));
    System.out.println("for MyresourceBundle, ja, zz"
    );
    System
    .out.println(rb.getClass());
    System.out.println(rb.getObject("today"
    ));
    System.out.println("---------------------------");

      rb = ResourceBundle.getBundle("MyresourceBundle",new Locale("fr","zz"));
      System.out.println("for MyresourceBundle, fr, zz");
      System.out.println(rb.getClass());
      System.out.println(rb.getObject("today"));
      System.out.println("---------------------------");

      rb = ResourceBundle.getBundle("MyresourceBundle",new Locale("en","xx"));
      System.out.println("for MyresourceBundle, en, xx");
      System.out.println(rb.getClass());
      System.out.println(rb.getObject("today"));
      System.out.println("---------------------------");
      
     rb = ResourceBundle.getBundle("MyresourceBundle",new Locale("xx","zz"));
      System.out.println("for MyresourceBundle, xx, zz");  
      System.out.println(rb.getClass());
      System.out.println(rb.getObject("today"));
      System.out.println("---------------------------");

       }
    }

    On building my project I get the following output:

    for MyresourceBundle,locale japan
    class java.util.PropertyResourceBundle
    Japan_Monday
    ---------------------------
    for MyresourceBundle_ja
    class java.util.PropertyResourceBundle
    Japan_Monday
    ---------------------------
    for MyresourceBundle, locale french
    class java.util.PropertyResourceBundle
    Monday
    ---------------------------

    for MyresourceBundle, ja, zz
    class java.util.PropertyResourceBundle
    Japan_Monday
    ---------------------------
    for MyresourceBundle, fr, zz
    class java.util.PropertyResourceBundle
    Monday
    ---------------------------
    for MyresourceBundle, en, xx
    class java.util.PropertyResourceBundle
    Monday
    ---------------------------
    for MyresourceBundle, xx, zz
    class java.util.PropertyResourceBundle
    Monday
    ---------------------------

    Hope this helps. If you are still facing problems do let me know.

    Thanks,
    Ritesh.

  • sdknewbie

    AARGH!

    Ok, I copied your project - and it ran fine. So then I copied my resources over, used your project, and it ran fine. Then I created a C# console project and called a java dll project that was like yours, using my resources - and it worked.

    But the same code in my app does not work - the very same code.

    Any ideas I would really like to get this working.

    thanks - dave

  • ResourceBundle problem