title: Save hash map Shared Preferences
body: <p>I'm triyng to save an HashMap into SharedPreferences but i get this error when i load the map:</p>
  
  <p>java.lang.ClassCastException: org.json.JSONArray cannot be cast to java.util.List</p>
  
  <p>I adapted the code i found online but i don't understand why i get this error.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>public static Map&lt;String, List&lt;Integer&gt;&gt; loadMap() {
      Map&lt;String,List&lt;Integer&gt;&gt; outputMap = new HashMap&lt;&gt;();
      SharedPreferences pSharedPref =             MainActivity.getContextofApplication().getSharedPreferences(NETWORK_PREF, Activity.MODE_PRIVATE);
      try{
          if (pSharedPref != null){
              String jsonString = pSharedPref.getString(RSSI_MAP, (new JSONObject()).toString());
              JSONObject jsonObject = new JSONObject(jsonString);
              Iterator&lt;String&gt; keysItr = jsonObject.keys();
              while(keysItr.hasNext()) {
                  String key = keysItr.next();
                  List&lt;Integer&gt; value = (List&lt;Integer&gt;) jsonObject.get(key);
                  outputMap.put(key, value);
              }
          }
      }catch(Exception e){
          e.printStackTrace();
      }
      return outputMap;
  }
  
  public void saveRSSI() {
      SharedPreferences pref = MainActivity.getContextofApplication().getSharedPreferences(NETWORK_PREF,Activity.MODE_PRIVATE);
      JSONObject jsonObject = new JSONObject(this.RSSImap);
      String jsonString = jsonObject.toString();
      SharedPreferences.Editor editor = pref.edit();
      editor.putString(RSSI_MAP, jsonString);
      editor.commit();
  }
  </code></pre>