I’m using the GWT’s Constants Interface. i have an instance class class that create a Java instance of MyConstants using the GWT.create(Class) facility, and then hold it, for the use of other.
public class LocaleMsgReader {
private static LocaleMsgReader INSTANCE = new LocaleMsgReader();
private static ErrorMessages errorMessages;
private LocaleMsgReader () {
}
public void init (){
errorMessages = (ErrorMessages) GWT.create(ErrorMessages.class);
}
public ErrorMessages getErrorMessages() {
return errorMessages;
}
public static LocaleMsgReader getInstance() {
return INSTANCE;
}
}
on the init method the it create the java instance, but when i calling the method getErrorMessages(), i get null.
why?
You’re making a singleton instance for LocalMsgReader so make errorMessages a instance variable instead of a class variable by removing static, and instantiate it in the constructor.