getBundle()

K

keepa

I am trying to load some resources but it is failing with a
MissingResourceException.

First, I have defined my resources as such:

public class AssyrianResources_at extends ListResourceBundle
{
// resoruces here
}

then I attempt to load it like this:

Locale locale = new Locale("at");
ResourceBundle getBundle("AssyrianResources", locale);

But this fails with a MissingResourceException.

Any ideas? It seems it cannot find my resource class. It is in the same
directory as all of my other class files.

On a related note, when I attempt to format a date with the above
locale ("at"), it fails ( I get the default American locale). The code
looks like this:

Locale locale = new Locale("at");
GregorianCalendar cal = new GregorianCalendar();
String format = "a format string";
String result = String.format(locale, format, cal);

This gives me an English formatted date, not an Assyrian formatted
date. I assume it is related to the above, where it cannot find the
resource bundle.
 
J

John O'Conner

keepa said:
I am trying to load some resources but it is failing with a
MissingResourceException.

First, I have defined my resources as such:

public class AssyrianResources_at extends ListResourceBundle
{
// resoruces here
}

then I attempt to load it like this:

Locale locale = new Locale("at");
ResourceBundle getBundle("AssyrianResources", locale);

But this fails with a MissingResourceException.


The ResourceBundle scheme typically wants the base class to exist too.
So you should start with Resources, then create Resources_at, etc. Then
you can load the "at" resources like this:

Locale locale = new Locale("at");
ResourceBundle resources = ResourceBundle.getBundle("Resources", locale);


Any ideas? It seems it cannot find my resource class. It is in the same
directory as all of my other class files.

You should use the full package name of the resource file. So, if you
are creating "com.keepa.Resources" and "com.keepa.Resources_at", you
should load using this:

ResourceBundle resources =
ResourceBundle.getBundle("com.keepa.Resources", locale);


On a related note, when I attempt to format a date with the above
locale ("at"), it fails ( I get the default American locale). The code
looks like this:



Have you checked whether DateFormat supports the "at" locale? Find out
using DateFormat.getAvailableLocales().


Regards,
John O'Conner
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,001
Messages
2,570,254
Members
46,849
Latest member
Fira

Latest Threads

Top