title: how to add and get class's object values in HashMap
body: <p>I want to create a method to add data into <code>sqlite</code> database which take <code>HashMap&lt;String,Person&gt;</code> as argument in a class.</p>
  
  <p>From another class, I want to add person details in <code>HashMap&lt;String,Person&gt;</code> that can be used by my database handler class.</p>
  
  <p>I have search a lot and tried many examples for this, but couldn't get the solution. Now i'm bit confused how to do this.</p>
  
  <p>I am doing this in following manner now, and getting <code>ClassCastException</code>.</p>
  
  <p><strong>Class 1 :PersonDataSource.java</strong></p>
  
  <pre><code>public long createContact(HashMap&lt;String, Contact&gt; queryValues) {
  ContentValues values = new ContentValues();    
  Contact val = Contact.class.cast(queryValues);   
  
  values.put(  MySQLiteHelper.COLUMN_FIRST_NAME,  val.getFirstName());
  values.put(  MySQLiteHelper.COLUMN_LAST_NAME, val.getLastName());
  values.put(  MySQLiteHelper.COLUMN_NICK_NAME, val.getNickName());
  values.put(  MySQLiteHelper.COLUMN_BIRTHDATE, val.getBirthDate());  
  values.put(  MySQLiteHelper.COLUMN_PRIMARY_CONTACT, val.getPrimaryContact());
  
  long insertId = database.insert(MySQLiteHelper.TABLE_NAME, null, values);
  return insertId;
  }
  </code></pre>
  
  <p>And form another class :</p>
  
  <pre><code>datasource = new ContactDataSource(this);
  datasource.open();
  
      Cursor phones = getContentResolver().query(Phone.CONTENT_URI, PROJECTION,null,null, Phone.DISPLAY_NAME);
          while (phones.moveToNext())
          {
            String name=phones.getString(phones.getColumnIndex(Phone.DISPLAY_NAME));
            String phoneNumber = phones.getString(phones.getColumnIndex(Phone.NUMBER));
  
            Person data = new Person();
            data.setNickName(name);
            data.setPrimaryContact(phoneNumber);
  
            HashMap&lt;String, Person&gt; map =  new  HashMap&lt;String, Person&gt;();
            map.put("data", data);
  
            long id = datasource.createContact(map);
  
            Log.e(CLASS_NAME, "Contact id :" + String.valueOf(id));
          }
          phones.close();
          datasource.close();
  </code></pre>
  
  <p>How can i solve this ?</p>