I have this code defined.
public class AAA {
public static final Map<String, String> gList = new HashMap<> {{
put("xxx", "xxx");
put ....
}};
public static AAA instance;
public static AAA getInstance() {
if (instance == null)
instance = new AAA();
return instance;
}
public String calledFunc(String k) {
return gList.get(k);
}
}
public class BBB {
...
public void callingFunc(String k) {
AAA.getInstance().calledFunc(k); // <= NULL pointer some time
}
}
Is this because memory allocation failure or it will be freed some where. Just don't understand what wrong in my code. Maybe this is not reliable way to initialize.