title: Android: Get single value from Hashmap Arraylist?
body: <p>So basically, I have a database that uses Hashmapping.
  After I run a query, I'd like to output the ID's and store it in an array in another activity.
  After that, I'd like to access a single element from the array.</p>
  
  <p>Here's my code for the database</p>
  
  <pre><code>public ArrayList&lt;HashMap&lt;String, String&gt;&gt; getIDList() {
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; IDList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
      String selectQuery = "SELECT cardID FROM flashcards";
      SQLiteDatabase database = this.getWritableDatabase();
  
      Cursor cursor = database.rawQuery(selectQuery, null);
      if(cursor.moveToFirst()) {
          do { HashMap&lt;String, String&gt; cardMap = new HashMap&lt;String, String&gt;();
          cardMap.put("cardID", cursor.getString(0));
          IDList.add(cardMap);
  
          } while(cursor.moveToNext());
      }
      return IDList;
  </code></pre>
  
  <p>This is the code where I am trying to access the elements. In this case, I'd like to access the first element. But an error </p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_flashcards_random);
  
  
      TextView currentID = (TextView) findViewById(R.id.currentIdText);
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; IDList = dbTools.getIDList();
      currentID.setText((IDList.get(0)).toString());
  
  
  
  }
  </code></pre>
  
  <p>any suggestions? </p>
  
  <p>EDIT: More code as requested. </p>
  
  <p>This is DB Tools code</p>
  
  <pre><code>    package com.izulki.flipper;
  
  import java.util.ArrayList;
  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 DBTools extends SQLiteOpenHelper {
  
  
      public DBTools(Context applicationContext){
          super(applicationContext, "flashcards.db", null, 1);
      }
  
      String DBName = "flashcards";
  
      @Override
      public void onCreate(SQLiteDatabase database) {
          String query = "CREATE TABLE flashcards (cardID INTEGER PRIMARY KEY, question VARCHAR, answer VARCHAR, subject VARCHAR, answered INTEGER, correct INTEGER)";
          database.execSQL(query);
  
      }
  
      @Override 
      public void onUpgrade(SQLiteDatabase database, int oldVersiom, int newVersion) {
          String query = "DROP TABLE IF EXISTS flashcards";
  
          database.execSQL(query);
          onCreate(database);
  
      }
  
      public boolean checkCard(String CardID) {
          SQLiteDatabase database = this.getReadableDatabase();
          Cursor cursor = database.rawQuery("SELECT * FROM flashcards WHERE CardID = ? ", new String[]{CardID});
                  boolean exists = (cursor.getCount() &gt; 0);
          cursor.close();
          return exists;
  
      }
  
      public void insertCard(HashMap&lt;String, String&gt; queryValues) {
  
          SQLiteDatabase database = this.getWritableDatabase();
          ContentValues values = new ContentValues();
          values.put("question", queryValues.get("question"));
          values.put("answer", queryValues.get("answer"));
          values.put("subject", queryValues.get("subject"));
          values.put("answered", 0);
          values.put("correct", 0);
  
          database.insert("flashcards", null, values);
          database.close();
  
      }
  
  
  
      public int getCardsCount() {
          String countQuery = "SELECT * FROM flashcards";
          SQLiteDatabase flashcards = this.getReadableDatabase();
          Cursor cursor = flashcards.rawQuery(countQuery, null);
          int cnt = cursor.getCount();
          cursor.close();
          return cnt;
      }
  
  
  
  
  
  
      public int updateCard(HashMap&lt;String, String&gt; queryValues) {
          SQLiteDatabase database = this.getWritableDatabase();
          ContentValues values = new ContentValues();
          values.put("question", queryValues.get("question"));
          values.put("answer", queryValues.get("answer"));
          values.put("subject", queryValues.get("subject"));
  
  
          return database.update("flashcards", values, 
                  "cardID" + " =?", new String[] {queryValues.get("cardID")});
      }
  
      public void resetCardStatistics(int cardID) {
          SQLiteDatabase database = this.getWritableDatabase();
          String resetQuery = "UPDATE flashcards SET answered = 0, correct = 0 WHERE CardID ='" + cardID + "'";
          database.execSQL(resetQuery);
      }
  
  
      public void deleteAllCards() {
          SQLiteDatabase database = this.getWritableDatabase();
          String deleteQuery = "Delete FROM flashcards";
          database.execSQL(deleteQuery);
  
      }
  
      public void deleteCard(int cardID) {
          SQLiteDatabase database = this.getWritableDatabase();
          String deleteQuery = "DELETE FROM flashcards WHERE CardID ='" + cardID + "'";
          database.execSQL(deleteQuery);
  
      }
  
  
  
      public ArrayList&lt;HashMap&lt;String, String&gt;&gt; getAllCards(){
          ArrayList&lt;HashMap&lt;String, String&gt;&gt; cardArrayList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
          String selectQuery = "SELECT * FROM flashcards ORDER BY subject";
          SQLiteDatabase database = this.getWritableDatabase();
  
          Cursor cursor = database.rawQuery(selectQuery, null);
          if(cursor.moveToFirst()){
              do{
                  HashMap&lt;String, String&gt; cardMap = new HashMap&lt;String, String&gt;();
                  cardMap.put("cardID", cursor.getString(0));
                  cardMap.put("question", cursor.getString(1));
                  cardMap.put("answer", cursor.getString(2));
                  cardMap.put("subject", cursor.getString(3));
  
              cardArrayList.add(cardMap);
              } while(cursor.moveToNext());
          }
          return cardArrayList;
      }
  
      public ArrayList&lt;HashMap&lt;String, String&gt;&gt; getCardsSubject(String subjectSearch) {
          ArrayList&lt;HashMap&lt;String, String&gt;&gt; subjectList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
          String selectQuery = "SELECT cardID FROM flashcards WHERE subject = '" + subjectSearch + "'";
          SQLiteDatabase database = this.getWritableDatabase();
  
          Cursor cursor = database.rawQuery(selectQuery, null);
          if(cursor.moveToFirst()) {
              do { HashMap&lt;String, String&gt; cardMap = new HashMap&lt;String, String&gt;();
              cardMap.put("cardID", cursor.getString(0));
              subjectList.add(cardMap);
  
              } while(cursor.moveToNext());
          }
          return subjectList;
  
      }
  
      public ArrayList&lt;HashMap&lt;String, String&gt;&gt; getIDList() {
          ArrayList&lt;HashMap&lt;String, String&gt;&gt; IDList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
          String selectQuery = "SELECT cardID FROM flashcards";
          SQLiteDatabase database = this.getWritableDatabase();
  
          Cursor cursor = database.rawQuery(selectQuery, null);
          if(cursor.moveToFirst()) {
              do { HashMap&lt;String, String&gt; cardMap = new HashMap&lt;String, String&gt;();
              cardMap.put("cardID", cursor.getString(0));
              IDList.add(cardMap);
  
              } while(cursor.moveToNext());
          }
          return IDList;
  
      }
  
      public HashMap&lt;String, String&gt; getQuestionFromID(int randomID) {
      HashMap&lt;String, String&gt; questionFinal = new HashMap&lt;String, String&gt;();
      SQLiteDatabase database = this.getReadableDatabase();
      String selectQuery = "SELECT question FROM flashcards WHERE cardID ='" + randomID + "'";
      Cursor cursor = database.rawQuery(selectQuery, null);
      if (cursor.moveToFirst()) {
          do{
          questionFinal.put("question", cursor.getString(0));
      } while (cursor.moveToNext());
      }
       return questionFinal;
      }
  
      public HashMap&lt;String, String&gt; getAnswerFromID(int randomID) {
          HashMap&lt;String, String&gt; answerFinal = new HashMap&lt;String, String&gt;();
          SQLiteDatabase database = this.getReadableDatabase();
          String selectQuery = "SELECT answer FROM flashcards WHERE cardID ='" + randomID + "'";
          Cursor cursor = database.rawQuery(selectQuery, null);
          if (cursor.moveToFirst()) {
              do{
              answerFinal.put("answer", cursor.getString(0));
          } while (cursor.moveToNext());
          }
           return answerFinal;
          }
  
      public void incrementCorrect(int ID){
          SQLiteDatabase database = this.getWritableDatabase();
          String incrementQuery = "UPDATE flashcards SET correct = correct +1 WHERE CardID = '" + ID + "'" ;
          database.execSQL(incrementQuery);
      }
  
      public void incrementAnswered(int randomID) {
          SQLiteDatabase database = this.getWritableDatabase();
          String incrementQuery = "UPDATE flashcards SET answered = answered +1 WHERE CardID = '" + randomID + "'" ;
          database.execSQL(incrementQuery);
      }
  
      public HashMap&lt;String, String&gt; getCardInfo(int randomID){
      HashMap&lt;String, String&gt; cardMap = new HashMap&lt;String, String&gt;();
      SQLiteDatabase database = this.getReadableDatabase();
      String selectQuery = "SELECT * FROM flashcards WHERE cardID ='" + randomID + "'";
  
      Cursor cursor = database.rawQuery(selectQuery, null);
      if(cursor.moveToFirst()){
          do{
  
              cardMap.put("cardID", cursor.getString(0));
              cardMap.put("question", cursor.getString(1));
              cardMap.put("answer", cursor.getString(2));
              cardMap.put("subject", cursor.getString(3));
              cardMap.put("answered", cursor.getString(4));
              cardMap.put("correct", cursor.getString(5));
  
          } while(cursor.moveToNext());
      }
          return cardMap;
  
      }
  }
  </code></pre>
  
  <p>This is the activity code</p>
  
  <pre><code>    package com.izulki.flipper;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.view.Menu;
  import android.widget.TextView;
  import android.widget.Toast;
  
  public class FlashcardsAnswer extends Activity {
  
      DBTools dbTools = new DBTools(this);
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_flashcards_random);
  
  
          TextView currentID = (TextView) findViewById(R.id.currentIdText);
          ArrayList&lt;HashMap&lt;String, String&gt;&gt; IDList = dbTools.getIDList();
          currentID.setText((IDList.get(0)).toString());
  
  
  
      }
  
  
  
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.flashcards_answer, menu);
          return true;
      }
  
  }
  </code></pre>
  
  <p>And this is the error</p>
  
  <pre><code>    02-21 15:02:55.777: E/AndroidRuntime(1827): FATAL EXCEPTION: main
  02-21 15:02:55.777: E/AndroidRuntime(1827): java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.IllegalStateException: Unable to get package info for com.izulki.flipper; is package not installed?
  02-21 15:02:55.777: E/AndroidRuntime(1827):     at android.app.LoadedApk.makeApplication(LoadedApk.java)
  02-21 15:02:55.777: E/AndroidRuntime(1827):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java)
  02-21 15:02:55.777: E/AndroidRuntime(1827):     at android.app.ActivityThread.access$1300(ActivityThread.java)
  02-21 15:02:55.777: E/AndroidRuntime(1827):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java)
  02-21 15:02:55.777: E/AndroidRuntime(1827):     at android.os.Handler.dispatchMessage(Handler.java)
  02-21 15:02:55.777: E/AndroidRuntime(1827):     at android.os.Looper.loop(Looper.java)
  02-21 15:02:55.777: E/AndroidRuntime(1827):     at android.app.ActivityThread.main(ActivityThread.java)
  02-21 15:02:55.777: E/AndroidRuntime(1827):     at java.lang.reflect.Method.invokeNative(Native Method)
  02-21 15:02:55.777: E/AndroidRuntime(1827):     at java.lang.reflect.Method.invoke(Method.java)
  02-21 15:02:55.777: E/AndroidRuntime(1827):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
  02-21 15:02:55.777: E/AndroidRuntime(1827):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
  02-21 15:02:55.777: E/AndroidRuntime(1827):     at dalvik.system.NativeStart.main(Native Method)
  02-21 15:02:55.777: E/AndroidRuntime(1827): Caused by: java.lang.IllegalStateException: Unable to get package info for com.izulki.flipper; is package not installed?
  02-21 15:02:55.777: E/AndroidRuntime(1827):     at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java)
  02-21 15:02:55.777: E/AndroidRuntime(1827):     at android.app.LoadedApk.getClassLoader(LoadedApk.java)
  02-21 15:02:55.777: E/AndroidRuntime(1827):     ... 12 more
  </code></pre>