Your code looks great. Just make sure you use the exact same key ( "b_StorageAvailable" ). Since a Boolean in Map automatically placed in a field with a primitive boolean value, if there is no entry in the Map for the entered key, you will get a NullPointerException .
I would also like to check that the type of the returned function and the local variable are also defined as HashMap<String, Boolean> . If it is untyped, then you cannot consider it a Boolean in Map .
public static void main(String[] args) { Map<String, Boolean> states = new HashMap<String, Boolean>(); states.put("b_StorageAvailable", true); states.put("b_StorageWritable", true); if(states.get("b_StorageAvailable")){ // works fine! System.out.println("storage is available!"); } Map states2 = new HashMap<String, Boolean>(); // untyped! states.put("b_StorageAvailable", true); states.put("b_StorageWritable", true); if(states2.get("b_StorageAvailable")){ // Type mismatch: cannot convert from Object to boolean System.out.println("storage is available!"); } }
So all you have to do is change
Map states = this.getExternalStorageStatus();
to
Map<String, Boolean> states = this.getExternalStorageStatus();
And potentially change the return type getExternalStorageStatus()
private Map<String,Boolean> getExternalStorageStatus(){ ... }
source share