I have a method in a class that initializes a HashMap and puts some keys and values ββinto it, then the method returns a HashMap. How to get returned HashMap?
public Map<String, String> getSensorValue(String sensorName) { registerSensor(sensorName); sensorValues.put("x","25"); sensorValues.put("y","26"); sensorValues.put("z","27"); return sensorValues; }
And here I call this method from another class:
public static HashMap<String, String> sensValues = new HashMap<String, String>(); AllSensors sensVal = new AllSensors(); sensValues.putAll(sensVal.getSensorValue("orientation")); String something = sensValues.get("x");
But it doesnβt work that way
sensValues.putAll(sensVal.getSensorValue("orientation"));
Makes Android app crash. The point is to somehow bring back the HashMap.
source share