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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:17:56+00:00 2026-06-17T02:17:56+00:00

I am getting cursor index out of bounds index 0 requested: with size 0.

  • 0

I am getting cursor index out of bounds “index 0 requested: with size 0”. Its just a user registration and login application. When there is no user with matching Username and Password my application is getting crashed.

Below is the code:

MainActivity.java

final SUSQLiteHelper dbhelper = new SUSQLiteHelper(this);

LoginData login = dbhelper.readOneUser(loginuname.getText().toString(), loginpwd.getText().toString());

                if(login.getUname().toString().equals(loginuname.getText().toString()) && 
                        login.getPwd().toString().equals(loginpwd.getText().toString()))
                {
                    Toast.makeText(getApplicationContext(), "Login Successfull. Welcome " + login.getUname().toUpperCase() +" !".toString(), 
                            Toast.LENGTH_LONG).show();
                }
                else if(login.getUname().toString().equals(loginuname.getText().toString()) && 
                            !login.getPwd().toString().equals(loginpwd.getText().toString()))
                {                       
                    Toast.makeText(getApplicationContext(), "Login Failed. Incorrect password !", 
                            Toast.LENGTH_LONG).show();                      
                }
                else
                    Toast.makeText(getApplicationContext(), "Login Failed. User doesn't exist !", 
                            Toast.LENGTH_LONG).show(); //it never goes here if no username is found in the table

SUSQLiteHelper.java

    public LoginData readOneUser(String uname, String pwd)
{
    SQLiteDatabase loginUserDB = this.getReadableDatabase();
    LoginData newLogin = null;
    Cursor cursor = loginUserDB.query(TABLE_NAME, new String[]{TABLE_ROW_UNAME, TABLE_ROW_EMAIL, TABLE_ROW_PWD}, TABLE_ROW_UNAME + "=?",
            new String[]{String.valueOf(uname)}, null, null, null);

    if(cursor.moveToFirst())
    {
        newLogin = new LoginData(cursor.getString(0), cursor.getString(1), cursor.getString(2));
    }
    cursor.close();
    loginUserDB.close();
    return newLogin;
}

LoginData.java

This class has getter and setter methods for Uname, Pwd, Email fields and a constructor which takes these fields as arguments.

  • 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-17T02:17:57+00:00Added an answer on June 17, 2026 at 2:17 am

    CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0

    It means that cursor.moveToFirst() returns false and Cursor is empty. So try to add the snippet for checking whether cursor is null or not and depends upon that modify your logic.

    public LoginData readOneUser(String uname, String pwd)
    {
     SQLiteDatabase loginUserDB = this.getReadableDatabase();
     LoginData newLogin = null;
     Cursor cursor = loginUserDB.query(TABLE_NAME, new String[]{TABLE_ROW_UNAME, TABLE_ROW_EMAIL,TABLE_ROW_PWD}, TABLE_ROW_UNAME + "=?",new String[]{String.valueOf(uname)}, null, null, null);
    
      if(cursor!=null) //Check whether cursor is null or not
      {
       if(cursor.moveToFirst())
       {
         newLogin = new LoginData(cursor.getString(0), cursor.getString(1), cursor.getString(2));
       }
      }
    cursor.close();
    loginUserDB.close();
    return newLogin;
     }
    

      LoginData login = dbhelper.readOneUser(loginuname.getText().toString(), loginpwd.getText().toString());
      if(login!=null)
       {
         //check for incorrect username or password
        }
      else
       {
         //Notify that no Username available with these Username
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting cursor index out of bounds index 0 requested: with size 0
I am getting a Cursor Index out of bounds error after opening a database
Hey I am getting index out of bounds error in my code. From Activity:
Are there any javascript Rich Text Editors that support getting and setting the cursor
I am getting Index was out of range. Must be non-negative and less than
Ok, guys, here's my code for getting SMS: Cursor cursor = getContentResolver().query(Uri.parse(uri), null, CallLog.Calls.DATE
Having this line Cursor c = db.rawQuery(PRAGMA table_info(?), new String[] {tableName}); and getting this:
Getting this out of the way; I don't frequently do much in php or
I have used cursor on sqlite db for getting records . My code is
Hey, I am Just Learning CoffeeScript and I Keep getting Errors. Here is my

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.