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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:05:31+00:00 2026-05-29T05:05:31+00:00

I don’t know why my cursor is empty. I read other 4-5 questions which

  • 0

I don’t know why my cursor is empty. I read other 4-5 questions which contain the same message but I couldn’t fix my problem. What did I forget?

With this code I got the message: “Cursor is empty”:

    public void onClick(View arg0) {
        String txt_edit_hw = edit_hw.getText().toString(); 
        ContentValues args = new ContentValues();
        args.put("hw", txt_edit_hw);

        String test = "SELECT _id FROM tbl_homework where hw='"+ txt_edit_hw +"';";

        Cursor mCursor = db.rawQuery(test, null); 

        startManagingCursor(mCursor);
        if (mCursor.moveToFirst()){

        String hw = mCursor.getString(mCursor.getColumnIndex("hw"));


        doMessage(hw);
        db.update("tbl_homework", args, "_id=34", null);
        fillData();
        } else {
            doMessage("Cursor is empty");
        }
    }

With this code I got the crach… android Index 0 requested, with a size of 0:

    public void onClick(View arg0) {
        String txt_edit_hw = edit_hw.getText().toString(); 
        ContentValues args = new ContentValues();
        args.put("hw", txt_edit_hw);

        String test = "SELECT _id FROM tbl_homework where hw='"+ txt_edit_hw +"';";

        Cursor mCursor = db.rawQuery(test, null); 

        startManagingCursor(mCursor);
        mCursor.moveToFirst();

        String hw = mCursor.getString(mCursor.getColumnIndex("hw"));

        doMessage(hw);
        db.update("tbl_homework", args, "_id=34", null);
        fillData();
    }

Same error this way: It crashes at the String (I commented it)

        public void onClick(View arg0) {
        String txt_edit_hw = edit_hw.getText().toString(); 
        txt_edit_hw.trim();
        ContentValues args = new ContentValues();
        args.put("hw", txt_edit_hw);

        String test = "SELECT _id FROM tbl_homework where hw='"+ txt_edit_hw +"';";

        Cursor mCursor = db.rawQuery(test, null); 

        startManagingCursor(mCursor);
        mCursor.moveToFirst();

        /**It crashes here**/String hwl = mCursor.getString(mCursor.getColumnIndex("_id"));

        doMessage(hwl);
        db.update("tbl_homework", args, "_id=34", null);
        fillData();
    }

02-06 12:13:49.789: I/Process(6112): Sending signal. PID: 6112 SIG: 9
02-06 12:13:55.582: D/dalvikvm(6140): GC_EXTERNAL_ALLOC freed 37K, 49% free 2785K/5379K, external 5211K/5218K, paused 23ms
02-06 12:13:58.785: D/AndroidRuntime(6140): Shutting down VM
02-06 12:13:58.785: W/dalvikvm(6140): threadid=1: thread exiting with uncaught exception (group=0x40091568)
02-06 12:13:58.796: E/AndroidRuntime(6140): FATAL EXCEPTION: main
02-06 12:13:58.796: E/AndroidRuntime(6140): android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
02-06 12:13:58.796: E/AndroidRuntime(6140):     at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
02-06 12:13:58.796: E/AndroidRuntime(6140):     at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
02-06 12:13:58.796: E/AndroidRuntime(6140):     at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
02-06 12:13:58.796: E/AndroidRuntime(6140):     at test.marco.notenha.homework$3.onClick(homework.java:227)
02-06 12:13:58.796: E/AndroidRuntime(6140):     at android.view.View.performClick(View.java:2486)
02-06 12:13:58.796: E/AndroidRuntime(6140):     at android.view.View$PerformClick.run(View.java:9130)
02-06 12:13:58.796: E/AndroidRuntime(6140):     at android.os.Handler.handleCallback(Handler.java:587)
02-06 12:13:58.796: E/AndroidRuntime(6140):     at android.os.Handler.dispatchMessage(Handler.java:92)
02-06 12:13:58.796: E/AndroidRuntime(6140):     at android.os.Looper.loop(Looper.java:130)
02-06 12:13:58.796: E/AndroidRuntime(6140):     at android.app.ActivityThread.main(ActivityThread.java:3703)
02-06 12:13:58.796: E/AndroidRuntime(6140):     at java.lang.reflect.Method.invokeNative(Native Method)
02-06 12:13:58.796: E/AndroidRuntime(6140):     at java.lang.reflect.Method.invoke(Method.java:507)
02-06 12:13:58.796: E/AndroidRuntime(6140):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
02-06 12:13:58.796: E/AndroidRuntime(6140):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
02-06 12:13:58.796: E/AndroidRuntime(6140):     at dalvik.system.NativeStart.main(Native Method)

Table:
Rows: _id, hwdate, hw
Val : “34” , “05/02/12”, “hy,xsdhagsah”

  • 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-29T05:05:32+00:00Added an answer on May 29, 2026 at 5:05 am

    Simply it says that your Cursor is not having any value and still you are trying to read from your Cursor. So, its always better to check the value of cursor.getCount();

    Log.d("Count",String.valueOf(cursor.getCount())); 
    if(cursor.getCount() > 0){
    // get values from cursor here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know where else to ask, but from one day to the other my
Don't really know how to formulate the title, but it should be pretty obvious
Don't know how to google for such, but is there a way to query
Don't know if I worded the question right, but basically what I want to
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know how to explain it better but i'm trying to get a response
Don't know whats exactly going on, but it's definitely killing my time for nothing.
Don't know if this is the right place to ask this, but I will
Don't know why, but sometimes LocationManager is still working also after closing application. I
Don't know if this is an eclipse specific problem but whenever I declare a

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.