Reputation: 10366
I'm at a loss as to how to use a resourcebundle in a blackberry app. I've made a class that extends ResourceBundle and overrides handleGetObject, but then when I say something like
ResourceBundle bundle = new EnglishBundle();
MenuItem example = new MenuItem(bundle, bundle.EXAMPLE, o, p);
addMenuItem(example);
I get null pointer exceptions. What am I doing wrong?
Upvotes: 2
Views: 1193
Reputation: 3065
Let's say the resource bundle files that you have created are called Local.rrc and Local.rrh.
Your class will need to implement LocalResource. Yes that is just the name I chose above + Resource.
E.g.
public class FooScreen extends MainScreen implements LocalResource {
private static ResourceBundle _res = ResourceBundle.getBundle(BUNDLE_ID, BUNDLE_NAME);
...
System.out.println(_res.getString(SOMESTRING)); // where SOMESTRING exists in your resource file
The names of the files are clearly important here, assuming the above file default is for the English Strings, the Spanish file would need to be called Local_es.rrc. Creating this file would give you an es tab on your strings editing screen and will automatically use the correct set of strings based on the phones current language setting.
Upvotes: 1
Reputation: 22978
You could use a different constructor for MenuItem:
ResourceBundle bundle = new
ResourceBundle.getBundle(EnglishBundle.BUNDLE_NAME);
MenuItem example = new MenuItem(bundle, EnglishBundle.EXAMPLE, o, p);
addMenuItem(example);
Upvotes: 0