I am porting my Android app to its cross-platform version (to have the iOS version) by means of Codename One.
I would like to use string resources like in the Android version.
I created a localization bundle (named "Localization (L10N) 1") only with english words for now.
In the main form I put this:
theme = UIManager.initFirstTheme("/theme");
String lang= L10NManager.getInstance().getLanguage();
UIManager.getInstance().setBundle(theme.getL10N("Localization (L10N) 1",lang));
In another container class I have:
String StringRes(String id)
{
String result;
result=UIManager.getInstance().getBundle().get(id);
return result;
}
when I need a string, for example:
add(new Label(StringRes("title_string")));
I get null pointer error in StringRes method.
I know that it is just an attempt to manage string resources.
What is the right way?
You are over thinking this... Codename One is localizable by default unlike any other framework I'm personally aware of.
Once you set the bundle value all you need to do is use the label with the right key e.g.:
add(new Label("title_string"));
It will "just work". Also you can use:
String value = getUIManager().localize("title_string", "This will show if title_string is missing from the bundle");
So StringRes
isn't the right direction.