Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9140143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:28:40+00:00 2026-06-17T09:28:40+00:00

Im attempting to develop an android program that has a user select an item

  • 0

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.

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

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

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?

Hopefully someone can give me a push in the right direction.

again

Here’s my code. 2 method in my DB helper class to get the name and age from the DB:

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;

Class for the listview, passing the id variable and starting the intent:

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);
}

Last class which opens from the intent and displays the name and age on the onCreate:

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);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:28:40+00:00Added an answer on June 17, 2026 at 9:28 am

    Can you spot your error?

     i.putExtra("passID", id);
     id = extras.getLong("passedID"); 
    

    It can be wise to store Extra-names as constants to eliminate typos

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to develop an Android app that allows a user to write
The self-extracting executable that I'm attempting to develop is an installer. An end-user will
I am attempting to develop a Drupal module that defines the class MyFeedsSyndicationParser. This
I am attempting to develop an Android application that sends and receives SMS messages
I am attempting to develop an SQL field that is the sum of all
I am attempting to develop a service that contains numerous client and server sockets
Attempting to use the data series from this example no longer passes the JSONLint
I am attempting to learn how to develop on the Android platform but do
I'm attempting to develop a simple online editor that allows for real-time collaboration (written
I am attempting to develop an application that makes use of some simple trig

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.