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 7554607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:22:54+00:00 2026-05-30T11:22:54+00:00

I have a database with the following method: public void deleteNote(long rowId) { mDb.delete(DATABASE_TABLE,

  • 0

I have a database with the following method:

    public void deleteNote(long rowId) { 
    mDb.delete(DATABASE_TABLE, KEY_REALROWID + "=" + rowId, null); 
    int x = (int) rowId; 
    int y = testCount(); 
    while(x<y) 
    {x++; 
    Cursor note= fetchNote(x); 
    ContentValues argsan = new ContentValues(); 
    argsan.put(KEY_REALROWID, x-1); 
    long z = Integer.valueOf(note.getString
(note.getColumnIndexOrThrow(NotesDbAdapter.K EY_ROWID))); 
    mDb.update(DATABASE_TABLE, argsan, KEY_ROWID + "=" + z, null); 
                }} 

The insert method is this:

public void createNote(double value, String isroot, String ispower, 
String ismultiply, String isdivisor, String add, 
String issubtract, double roototpowerval, String 
paranthaseesend, String paranthaseesstart) { 
ContentValues initialValues = new ContentValues(); 
initialValues.put(KEY_VALUE, value); 
initialValues.put(KEY_ISROOT, isroot); 
initialValues.put(KEY_ISPOWER, ispower); 
initialValues.put(KEY_ISMULTIPLIER, ismultiply); 
initialValues.put(KEY_ISDIVISOR, isdivisor); 
initialValues.put(KEY_ISADD, add); 
initialValues.put(KEY_ISSUBTRACT, issubtract); 
initialValues.put(KEY_POWERORROOTNUMBER, roototpowerval); 
initialValues.put(KEY_REALROWID, testCount()+1); 
initialValues.put(KEY_ISPE, paranthaseesend); 
initialValues.put(KEY_ISPS, paranthaseesstart); 
mDb.insert(DATABASE_TABLE, null, initialValues); 
    } 

The testCount() method is this:

public int testCount() {
     Cursor c = mDb.rawQuery("select count(*) from notes", null);
     int tst = 0;
     if (c.moveToNext()) {
         tst = c.getInt(c.getColumnIndex("count(*)"));
     }
     return tst;
    }

The fetch method is this:

    public Cursor fetchNote(long rowId) throws SQLException { 
    Cursor mCursor = mDb.query(true, DATABASE_TABLE, new String[] 
    {KEY_ISPS,KEY_ISPE,KEY_VALUE, 
    KEY_ISROOT,KEY_REALROWID,KEY_ISPOWER,KEY_POWERORROOTNUMBER,KEY_ISDIVISOR,
KEY_ISMULTIPLIER, KEY_ISADD,KEY_ISSUBTRACT}, 
    KEY_REALROWID + "=" + rowId, null, null, null, null, null); 
    if (mCursor != null) { 
    mCursor.moveToFirst(); 
    } 
    return mCursor; 
        } 

When I run this I get an error:

    mDbHelper.createNote(d, "false", "false", "false", "false",
 "false", "false", 0, "false", "false"); 
    mDbHelper.createNote(0, "false", "false", "false","false",
 "false", "true", 0, "false", "false"); 
    mDbHelper.createNote(d, "false", "false", "false","false",
"false", "false", 0, "false", "false"); 
    mDbHelper.createNote(d, "false", "false", "false","false",
 "false", "false", 0, "false", "false"); 
    mDbHelper.deleteNote(3); 
    Cursor c = mDbHelper.fetchNote(3);

Here is my LogCat:

FATAL EXCEPTION: main
android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
at com.real.AlgebraActivity$1.onClick(AlgebraActivity.java:301)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)

As always thanks for any help.

  • 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-05-30T11:22:55+00:00Added an answer on May 30, 2026 at 11:22 am

    Ok i think i found the root of your Exception.
    In the activity onClick() method you create(and insert in the DB) 4 notes, delete one(note 3) and then you fetch the note 3(this should be note 4 that has become note 3). What you didn’t post post from that method is other lines after the line Cursor c = mDbHelper.fetchNote(3); where most likely you try to use that cursor c.

    The problem is that your deleteNote() method works as you designed it:
    – deletes the note with the id (3 in you example)
    – x=3 and y becomes 3(you have deleted one row from the 4 that you inserted) so when you get to the while loop (x < y) the condition is false so you never enter in to the loop to update the note 4 to become note 3.
    Now your database has a structure like this:

    note 1
    note 2
    note 4
    

    Then you try to fetch the note 3 that doesn’t exist and you end up with an empty cursor c on which you try to work and throws the CursorIndexOutOfBoundsException.

    To resolve the issue try to update your logic so you don’t end up with empty spaces in the KEY_REALROWID column. (I haven’t tested but try to put while(x <= y) in the deleteNote() method).
    Well this is what i think it’ happening.

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

Sidebar

Related Questions

I have the following method: public IEnumerable<Foo> GetFoo(int x, string y) { return from
I have two database tables with the following structure: actions: action_id int(11) primary key
I use the following code to add rows to my database : public void
I have the following method that drops the database but I get a syntax
I have the following method being called in a Java EE web application. public
I have the following code: public void doJob() { MyObj s; for ( Object
Let's say I have the following code: public void doSomething() { // begin transaction
Currently I have database with the following associations: One Client to Many Intakes One
I have the following database table created thus: CREATE TABLE AUCTIONS ( ARTICLE_NO VARCHAR(20),
I have a database in the following format: ID TYPE SUBTYPE COUNT MONTH 1

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.