title: How to retrieve data from database table by Username?
body: <p>I'm not too sure whether it's appropriate that using 'username' as my selection to retrieve other data instead of using an id. FYI, my username is unique as there will not be any other user having the same username. I'm doing this way because I'm not sure how to use or call the id  from the table.
  I'm getting this error:</p>
  
  <pre><code>    CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
  </code></pre>
  
  <p>I have a DatabaseAdapter.java with this code:</p>
  
  <pre><code>   public Cursor getData(String username){
        SQLiteDatabase db = dbHelper.getReadableDatabase();
        Cursor cur =  db.query(TABLE_PROFILE, COLUMNS_PROFILE, " username=?", new String[]{username}, null, null, null, null );
        if (cur != null){
            cur.moveToFirst();
        }
        return cur;
     }
  </code></pre>
  
  <p>With a EditProfileFragment.java:</p>
  
  <pre><code>    dbAdapter = new DatabaseAdapter(getActivity());
      dbAdapter = dbAdapter.open();
  
      un = getArguments().getString("username");  
  
      Cursor cur = dbAdapter.getData(un);
      String password = cur.getString(cur.getColumnIndexOrThrow(DatabaseAdapter.KEY_PASSWORD));
      String age = cur.getString(cur.getColumnIndexOrThrow(DatabaseAdapter.KEY_AGE));
      String weight = cur.getString(cur.getColumnIndexOrThrow(DatabaseAdapter.KEY_WEIGHT));
      String height = cur.getString(cur.getColumnIndexOrThrow(DatabaseAdapter.KEY_HEIGHT));
      String gender= cur.getString(cur.getColumnIndexOrThrow(DatabaseAdapter.KEY_GENDER));
  </code></pre>
  
  <p>I'm getting the String un in my log, means my username is successfully passed. I'm blur with the data retrieving data from the cursor, please help and thank you in advance for the help. </p>