title: How to clear the hash map<string,string> values?
body: <p>I want to clear all the hash map values before the values are assigned to hash map from db.For eg.,<code>hashmap&lt;string,string&gt; demo</code> is my hashmap in that i have added the following values from db.The result response from hashmap is <code>{A=1, B=2, C=3, D=4, E=5}</code>.After view loads I want to insert this in above hashmap <code>{A=test, B=demo, C=sample, D=empty, E=null}</code>.For this how can I clear the first values before inserting the second set of values.And also I have tried by using <code>demo.clear()</code> it is not working.How can I clear the 1st list of values before adding the 2nd one.Suggest some solutions to solve the problem.</p>
  
  <p>This is the code to retrieve data from db.</p>
  
  <pre><code>public HashMap&lt;String, String&gt; getdata() {
      try {
          HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
          Log.e("getdata", "Started");
          String selectQuery = "SELECT * FROM tablename";
          SQLiteDatabase database = this.getWritableDatabase();
          Cursor cursor = database.rawQuery(selectQuery, null);
          if (cursor.moveToFirst()) {
              do {
                  map.put(cursor.getString(cursor.getColumnIndex("colmn1")),
                          cursor.getString(cursor.getColumnIndex("colmn2")));
              } while (cursor.moveToNext());
          }
          cursor.close();
          return map;
  
      } catch (Exception e) {
          e.printStackTrace();
          Log.e("getdata", "Ended");
      }
      return null;
  
  }
  </code></pre>
  
  <p>In this demo only the response coming as I explained above.And then am doing this</p>
  
  <pre><code>if(demo.isEmpty())
          {
  //code for correct condition
          }
  else
      {
       demo.clear();
      }
  </code></pre>
  
  <p>And passing the values to hash map by this way.</p>
  
  <pre><code>demo = dbhelper.getdata();
  </code></pre>
  
  <p>And My Logcat exceptions:</p>
  
  <pre><code>09-06 12:48:53.656: W/dalvikvm(5071): threadid=1: thread exiting with uncaught exception (group=0x40fb0258)
  09-06 12:48:53.660: W/System.err(5071): java.lang.RuntimeException: Unable to start activity ComponentInfo{packagename/packagename.listdata}: java.lang.NullPointerException
  09-06 12:48:53.660: W/System.err(5071):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2077)
  09-06 12:48:53.660: W/System.err(5071):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
  09-06 12:48:53.660: W/System.err(5071):     at android.app.ActivityThread.access$600(ActivityThread.java:134)
  09-06 12:48:53.660: W/System.err(5071):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
  09-06 12:48:53.660: W/System.err(5071):     at android.os.Handler.dispatchMessage(Handler.java:99)
  09-06 12:48:53.660: W/System.err(5071):     at android.os.Looper.loop(Looper.java:154)
  09-06 12:48:53.660: W/System.err(5071):     at android.app.ActivityThread.main(ActivityThread.java:4624)
  09-06 12:48:53.661: W/System.err(5071):     at java.lang.reflect.Method.invokeNative(Native Method)
  09-06 12:48:53.661: W/System.err(5071):     at java.lang.reflect.Method.invoke(Method.java:511)
  09-06 12:48:53.661: W/System.err(5071):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
  09-06 12:48:53.661: W/System.err(5071):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
  09-06 12:48:53.661: W/System.err(5071):     at dalvik.system.NativeStart.main(Native Method)
  09-06 12:48:53.661: W/System.err(5071): Caused by: java.lang.NullPointerException
  09-06 12:48:53.661: W/System.err(5071):     at packagename.listdata.onCreate(listdata.java:231)
  09-06 12:48:53.661: W/System.err(5071):     at android.app.Activity.performCreate(Activity.java:4479)
  09-06 12:48:53.661: W/System.err(5071):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
  09-06 12:48:53.661: W/System.err(5071):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2041)
  </code></pre>