HI
I tried to run the following code. But it gave the error message that
"Can't find bundle for base name MessageBundle, locale en_US"
import java.util.*;
import java.text.*;
public class MessageFormatDemo {
static void displayMessage(Locale currentLocale) {
System.out.println("currentLocale = " + currentLocale.toString());
System.out.println();
ResourceBundle messages =
ResourceBundle.getBundle("MessageBundle",currentLocale);
Object[] messageArguments = {
messages.getString("planet"),
new Integer(7),
new Date()
};
MessageFormat formatter = new MessageFormat("");
formatter.setLocale(currentLocale);
formatter.applyPattern(messages.getString("template"));
String output = formatter.format(messageArguments);
System.out.println(output);
}
static public void main(String[] args) {
displayMessage(new Locale("en", "US"));
System.out.println();
displayMessage(new Locale("de", "DE"));
}
}
properties file:
# MessageBundle.properties_en_US
planet = Mars
template = At {2,time,short} on {2,date,long}, we detected \
{1,number,integer} spaceships on the planet {0}.
># MessageBundle.properties_en_US
Is it your file name?
No, you have to name it like that :
<file-name>_<language_code>_<contry-code>.properties
then your name have to be named: MessageBundle_en_US.properties not MessageBundle.properties_en_US
Good Luck
Ahmad Elsafty
you have to specify you complete bundle package path:
for example if your MessageBundle_en_US.properties file resides in the package com.example, you will write that:
ResourceBundle messages =
ResourceBundle.getBundle("com.example.MessageBundle",currentLocale);
Good Luck
Ahmad Elsafty
> I gave the full package name along with the name of the properties file.
> Even then i am getting the same type of error message.
Did you put the properties file in your classpath? It has to go in just the same location as a class of the same name would.
> Please note that i am working with netbeans.
That doesn't excuse you from learning about classpaths.