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

  • SEARCH
  • Home
  • 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 8130939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:55:02+00:00 2026-06-06T08:55:02+00:00

I have a program where you click a button, and a dialog pops up

  • 0

I have a program where you click a button, and a dialog pops up with a bunch of checkboxes. You choose a few of the checkboxes, and then click “ok”. What I am trying to do is have it so that when you press ok, for each value you checked off, it will search several database tables for rows containing that value, take information from those rows, and put them in a different table. For some reason I keep getting this cursor out of bounds exception and I honestly cannot figure out why. I tried a bunch of things that I found while searching and I cannot get it to work.

Here is what happens when you click ok:

ok.setOnClickListener(new View.OnClickListener(){
    public void onClick(View v) {

        if (dumbbells.isChecked()==true){
            equip = "dumbbells";
            AddToEquipTable(equip);
        }
        if (barbell.isChecked()==true){
            equip = "Barbell";
            AddToEquipTable(equip);
        }
        if (cablemachine.isChecked()==true){
            equip = "Cable Machine";
            AddToEquipTable(equip);
        }
        if (pullupbar.isChecked()==true){
            equip = "Pull Up Bar";
            AddToEquipTable(equip);
        }
        if (legpressmachine.isChecked()==true){
            equip = "Leg Press Machine";
            AddToEquipTable(equip);
        }
        if (legextensionmachine.isChecked()==true){
            equip = "Leg Extension Machine";
            AddToEquipTable(equip);
        }
        if (hamstringcurlmachine.isChecked()==true){
            equip = "Hamstring Curl Machine";
            AddToEquipTable(equip);
        }
        if (kettlebells.isChecked()==true){
            equip = "Kettlebells";
            AddToEquipTable(equip);
        }
        if (none.isChecked()==true){
            equip = "None";
            AddToEquipTable(equip);
        }


    }
});

Here is the “AddToEquipTable” method I created:

public void AddToEquipTable(String equip){

ExerciseDatabase equipment = new ExerciseDatabase(WorkMeOutActivity.this);
try {
    equipment.open();
} catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

equipment.AddToEquipmentDBFromBiceps(equip);
equipment.AddToEquipmentDBFromChest(equip);
equipment.AddToEquipmentDBFromBack(equip);
equipment.AddToEquipmentDBFromTriceps(equip);
equipment.AddToEquipmentDBFromShoulders(equip);
equipment.AddToEquipmentDBFromLegs(equip);
equipment.AddToEquipmentDBFromCompound(equip);

equipment.close();
}

And here is one of the methods it calls in my DB Helper Activity. They are all the same, except for the table name called.

public String AddToEquipmentDBFromBiceps(String equip) {
    // TODO Auto-generated method stub
    String[] columns = new String[]{KEY_REPS, KEY_EXERCISE, KEY_TIMETYPE};
    ContentValues cv = new ContentValues();
    Cursor c = ourDatabase.query(DATABASE_BICEPSTABLE, columns, KEY_EQUIP + "='" + equip + "'", null, null, null, null);

    if (c == null){
        return null;
    }
    else if(c != null){

        c.moveToFirst();

        int iReps = c.getColumnIndex(KEY_REPS);
        int iExercise = c.getColumnIndex(KEY_EXERCISE);
        int iTimeType = c.getColumnIndex(KEY_TIMETYPE);



        do{

            String reps = c.getString(iReps);
            String exercise = c.getString(iExercise);
            String time = c.getString(iTimeType);

            cv.put(KEY_REPS, reps);
            cv.put(KEY_EXERCISE, exercise); 
            cv.put(KEY_TIMETYPE, time);

            ourDatabase.insert(DATABASE_CHOSEN_EQUIP_TABLE, null, cv);

            c.moveToNext();

            }while(KEY_EQUIP == equip);
        }


    return null;
}

**Error Log After Changing Condition as Suggested Below:

06-24 09:34:42.785: E/AndroidRuntime(20592): FATAL EXCEPTION: main
06-24 09:34:42.785: E/AndroidRuntime(20592): android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
06-24 09:34:42.785: E/AndroidRuntime(20592):    at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
06-24 09:34:42.785: E/AndroidRuntime(20592):    at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
06-24 09:34:42.785: E/AndroidRuntime(20592):    at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
06-24 09:34:42.785: E/AndroidRuntime(20592):    at com.work.me.out.ExerciseDatabase.AddToEquipmentDBFromLegs(ExerciseDatabase.java:896)
06-24 09:34:42.785: E/AndroidRuntime(20592):    at com.work.me.out.WorkMeOutActivity.AddToEquipTable(WorkMeOutActivity.java:456)
06-24 09:34:42.785: E/AndroidRuntime(20592):    at com.work.me.out.WorkMeOutActivity$9.onClick(WorkMeOutActivity.java:395)
06-24 09:34:42.785: E/AndroidRuntime(20592):    at android.view.View.performClick(View.java:2538)
06-24 09:34:42.785: E/AndroidRuntime(20592):    at android.view.View$PerformClick.run(View.java:9152)
06-24 09:34:42.785: E/AndroidRuntime(20592):    at android.os.Handler.handleCallback(Handler.java:587)
06-24 09:34:42.785: E/AndroidRuntime(20592):    at android.os.Handler.dispatchMessage(Handler.java:92)
06-24 09:34:42.785: E/AndroidRuntime(20592):    at android.os.Looper.loop(Looper.java:130)
06-24 09:34:42.785: E/AndroidRuntime(20592):    at android.app.ActivityThread.main(ActivityThread.java:3687)
06-24 09:34:42.785: E/AndroidRuntime(20592):    at java.lang.reflect.Method.invokeNative(Native Method)
06-24 09:34:42.785: E/AndroidRuntime(20592):    at java.lang.reflect.Method.invoke(Method.java:507)
06-24 09:34:42.785: E/AndroidRuntime(20592):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
06-24 09:34:42.785: E/AndroidRuntime(20592):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
06-24 09:34:42.785: E/AndroidRuntime(20592):    at dalvik.system.NativeStart.main(Native Method)
  • 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-06T08:55:04+00:00Added an answer on June 6, 2026 at 8:55 am

    Probably you have bad condition, change yours with:

    while (c.moveToNext() && KEY_EQUIP == equip);
    

    Note: Also i recommend to you use parametrized statements which are more safe, faster and clearer.


    CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0

    It means that cursor.moveToFirst() returns false and Cursor is empty.
    So try to add this snippet and try it.

    else if(c != null && c.moveToFirst()) {
            int iReps = c.getColumnIndex(KEY_REPS);
            int iExercise = c.getColumnIndex(KEY_EXERCISE);
            int iTimeType = c.getColumnIndex(KEY_TIMETYPE);
            do {
                String reps = c.getString(iReps);
                String exercise = c.getString(iExercise);
                String time = c.getString(iTimeType);
    
                cv.put(KEY_REPS, reps);
                cv.put(KEY_EXERCISE, exercise); 
                cv.put(KEY_TIMETYPE, time);
    
                ourDatabase.insert(DATABASE_CHOSEN_EQUIP_TABLE, null, cv);
                } while (c.moveToNext() && KEY_EQUIP == equip);
            }
    

    Try to use rawQuery method similar like this:

    final String SELECT_QUERY = "SELECT " + KEY_REPS + ", " + KEY_EXERCISE + ", " + KEY_TIMETYPE + " FROM " + DATABASE_BICEPSTABLE + " WHERE " + KEY_EQUIP + " = ?";
    Cursor c = db.rawQuery(SELECT_QUERY, new String[] {equip});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that simulates mouse click. Code is something like this: [DllImport(user32.dll,
I have a rather confusing setup for a program that lets the user choose
I have a wpf application that has a button for for each folder under
So I have a program that dynamically compiles a new program at the click
I have one button when I click the button it shows the alert dialog
I have developed a program in PHP which opens IE on a button click.
In my program I have two JFrame instances. When I click next button I
I have a program, when I click button 'Download', program create a new thread
I have a program with an associated file type. However, when I double-click a
I have program that has a variable that should never change. However, somehow, it

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.