Null cursor return
<p>Im attempting to develop an android program that has a user select an item from a listmenu......then pass the ID of this item to an intent to a second class, the ID is then stored in a variable and is inputted into a DBhelper method to get the name and age of a person and display this data in their relevant EditTexts in the XML.</p>

<p>Everything works fine until I try to start the second intent. Im getting a error of:</p>

<pre><code>01-11 22:21:28.448: E/AndroidRuntime(274): java.lang.RuntimeException: Unable to start  activity ComponentInfo{com.example.sqliteexample/com.example.sqliteexample.DisplayContents}: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
</code></pre>

<p>Note that I have initialized the 'id' variable passed with '0'. this isn't being passed to the class methods to get the name and age?</p>

<p>Hopefully someone can give me a push in the right direction.</p>

<p>again</p>

<p>Here's my code. 2 method in my DB helper class to get the name and age from the DB:</p>

<pre><code>public String showData(long id) {

        String [] columns = new String[]{KEY_ROWID, KEY_NAME, KEY_HOTNESS};
        Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_ROWID + "=" + id, null, null, null, null);
        if(c != null)
        {
            // move to the selected row
        c.moveToFirst();
        String namePass = c.getString(1);
        return namePass;
        }
        return null;

        }

    public String showAge(long id) {

        String [] columns = new String[]{KEY_ROWID, KEY_NAME, KEY_HOTNESS};
        Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_ROWID + "=" + id, null, null, null, null);
        if(c != null)
        {
            // move to the selected row
        c.moveToFirst();
        String agePass = c.getString(2);
        return agePass;
        }
        return null;
</code></pre>

<p>Class for the listview, passing the id variable and starting the intent:</p>

<pre><code>public void onListItemClick(ListView list, View v, int list_posistion, long item_id)
{


    long id = item_id;
    Intent i = new Intent("com.example.sqliteexample.DisplayContents");
    i.putExtra("passID", id);
    startActivity(i);
}
</code></pre>

<p>Last class which opens from the intent and displays the name and age on the onCreate:</p>

<pre><code>package com.example.sqliteexample;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.content.Intent;

public class DisplayContents extends Activity implements OnClickListener  {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

setContentView(R.layout.displaycontents);

long id = 0;
EditText namePassed;
EditText agePassed;

namePassed = (EditText) findViewById(R.id.nameShow);
agePassed = (EditText) findViewById(R.id.ageShow);
HotOrNot display = new HotOrNot(this, null, null);


    Bundle extras = getIntent().getExtras(); 
    if (extras != null) {
        id = extras.getLong("passedID"); 
    }
    display.open();
    String returnedName = display.showData(id);
    String returnedAge  = display.showAge(id);

    namePassed.setText(returnedName);
    agePassed.setText(returnedAge);
</code></pre>
