title: Android SQLiteDatabase access via HashMap
body: <p>I tried to implement a <code>SQLiteDatabase</code> into my app to store data. However, I wrote a test project to get accustomed with the <code>SQliteDatabase</code>. It is fairly simple but still it won't work properly. The problem comes after the code(built for <code>GoogleAPI 7</code>).</p>
  
  <p><strong>SQLiteTestActicity :</strong> </p>
  
  <pre><code>package test.sqlite.db;
  
  import test.sqlite.db.lib.DatabaseHandler;
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Toast;
  
  public class SQLiteTestActivity extends Activity {
  
  private static final String KEY_ID = "id";
  private static final String KEY_NAME = "name";
  private static final String KEY_SURENAME = "surename";
  private static final String KEY_ADDRESS = "address";
  private static final String KEY_PHONE = "phone";
  private static final String KEY_UID = "uid";
  private static final String KEY_TIME = "time";
  private static final String KEY_COUNT = "count";
  private static final String KEY_DATE = "date";
  private static final String ORDERS_TABLE = "orders";
  
  EditText inputName;
  EditText inputSurename;
  EditText inputAddress;
  EditText inputUID;
  
  Button addUserBTN;
  Button getUserDetailsBTN;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      final DatabaseHandler db = new DatabaseHandler(getBaseContext());
  
      inputName = (EditText) findViewById(R.id.inputName);
      inputSurename = (EditText) findViewById(R.id.inputSurename);
      inputAddress = (EditText) findViewById(R.id.inputAddress);
      inputUID = (EditText) findViewById(R.id.inputUID);
  
      addUserBTN = (Button) findViewById(R.id.addUserBTN);
      addUserBTN.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
  
              try {
  
                  String name = inputName.getText().toString();
                  String surename = inputSurename.getText().toString();
                  String address = inputAddress.getText().toString();
                  String uid = inputUID.getText().toString();
  
                  db.addUser(name, surename, address, uid);
  
                  try {
  
                      Toast.makeText(getApplicationContext(), "Succes!",
                              Toast.LENGTH_LONG).show();
                      System.out.printf(name + "\n" + surename + "\n"
                              + address + "\n" + uid + "\n");
  
                  } catch (NullPointerException e) {
                      e.printStackTrace();
                  }
              } catch (NullPointerException e) {
                  e.printStackTrace();
              }
          }
  
      });
  
      getUserDetailsBTN = (Button) findViewById(R.id.getUserDetailsBTN);
      getUserDetailsBTN.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              try {
  
                  System.out.println(db.getUserDetails().toString());
  
              } catch (NullPointerException e) {
                  e.printStackTrace();
              }
  
          }
  
      });
  
  }
  }
  </code></pre>
  
  <p><strong>DatabaseHandler :</strong></p>
  
  <pre><code>package test.sqlite.db.lib;
  
  import java.util.HashMap;
  
  import android.content.ContentValues;
  import android.content.Context;
  import android.database.Cursor;
  import android.database.sqlite.SQLiteDatabase;
  import android.database.sqlite.SQLiteOpenHelper;
  
  public class DatabaseHandler extends SQLiteOpenHelper {
  
  private static final int DATABASE_VERSION = 1;
  private static final String USER_TABLE = "userT";
  static String DATABASE_NAME = "TAXIDB";
  
  private static final String KEY_ID = "id";
  private static final String KEY_NAME = "name";
  private static final String KEY_SURENAME = "surename";
  private static final String KEY_ADDRESS = "address";
  private static final String KEY_PHONE = "phone";
  private static final String KEY_UID = "uid";
  private static final String KEY_TIME = "time";
  private static final String KEY_COUNT = "count";
  private static final String KEY_DATE = "date";
  private static final String ORDERS_TABLE = "orders";
  
  public DatabaseHandler(Context context) {
      super(context, DATABASE_NAME, null, DATABASE_VERSION);
  }
  
  @Override
  public void onCreate(SQLiteDatabase db) {
      String CREATE_USER_TABLE = "CREATE TABLE IF NOT EXISTS " + USER_TABLE
              + "(" + KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT,"
              + KEY_SURENAME + " TEXT," + KEY_ADDRESS + " TEXT," + KEY_UID
              + " TEXT" + ")";
      db.execSQL(CREATE_USER_TABLE);
  
  //      String CREATE_ORDERS_TABLE = "CREATE TABLE IF NOT EXISTS "
  //              + ORDERS_TABLE + "(" + KEY_ID
  //              + " INTEGER PRIMARY KEY AUTOINCREMENT," + ")";
  //      db.execSQL(CREATE_ORDERS_TABLE);
  
  }
  
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      // TODO Auto-generated method stub
  
  }
  
  public void addUser(String name, String surename, String address, String uid) {
      SQLiteDatabase db = this.getWritableDatabase();
  
      ContentValues values = new ContentValues();
      values.put(KEY_NAME, name); // Name
      values.put(KEY_SURENAME, surename); // Surename
      values.put(KEY_ADDRESS, address);
      values.put(KEY_UID, uid);
  
      // Inserting Row
      db.insert(USER_TABLE, null, values);
      db.close(); // Closing database connection
  }
  
  public HashMap&lt;String, String&gt; getUserDetails(){
      HashMap&lt;String,String&gt; user = new HashMap&lt;String,String&gt;();
      String selectQuery = "SELECT  * FROM " + USER_TABLE;
  
      SQLiteDatabase db = this.getReadableDatabase();
      Cursor cursor = db.rawQuery(selectQuery, null);
      // Move to first row
      cursor.moveToFirst();
      if(cursor.getCount() &gt; 0){
          user.put("name", cursor.getString(1));
          user.put("surename", cursor.getString(2));
          user.put("address", cursor.getString(3));
          user.put("uid", cursor.getString(4));
      }
      cursor.close();
      db.close();
      // return user
      return user;
  }
  }
  </code></pre>
  
  <p><strong>Problem :</strong></p>
  
  <p>Whenever I press the <code>getUserDetailsBTN</code> I receive the following:</p>
  
  <p><strong>LogCat:</strong></p>
  
  <pre><code> {uid=android.widget.EditText@40523fa8, address=android.widget.EditText@40523418, surename=android.widget.EditText@40522888, name=android.widget.EditText@40520548}
  </code></pre>