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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:10:12+00:00 2026-05-31T00:10:12+00:00

I get an error when I try to retrieve from SQLite into an Array.

  • 0

I get an error when I try to retrieve from SQLite into an Array.
I identified the error cause in the for loop, error in the statement

urlString[i] = allrows.getString(0);

I tried to debug it but still I do not know how to solve it. The method as below:

public String[] getImgURL(){
        mydb = localContext.openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
        Cursor allrows  = mydb.rawQuery("SELECT ImgURL FROM "+  TABLE, null);
        String[] urlString = new String[allrows.getCount()-1];
        for (int i = 1; i < allrows.getCount(); i++) {
            urlString[i] = allrows.getString(0);
            allrows.moveToNext();               
        }
        allrows.close();    
        mydb.close();
        return urlString;
}

the log as follow

03-06 01:26:05.479: W/dalvikvm(27671): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)    
03-06 01:26:05.479: E/AndroidRuntime(27671): FATAL EXCEPTION: main    
03-06 01:26:05.479: E/AndroidRuntime(27671): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.testing/com.ip.scan.MainActivity}: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 5    
03-06 01:26:05.479: E/AndroidRuntime(27671):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java)    
03-06 01:26:05.479: E/AndroidRuntime(27671):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java)    
03-06 01:26:05.479: E/AndroidRuntime(27671):    at android.app.ActivityThread.access$1500(ActivityThread.java)    
03-06 01:26:05.479: E/AndroidRuntime(27671):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java)    
03-06 01:26:05.479: E/AndroidRuntime(27671):    at android.os.Handler.dispatchMessage(Handler.java)    
03-06 01:26:05.479: E/AndroidRuntime(27671):    at android.os.Looper.loop(Looper.java)    
03-06 01:26:05.479: E/AndroidRuntime(27671):    at android.app.ActivityThread.main(ActivityThread.java)
03-06 01:26:05.479: E/AndroidRuntime(27671):    at java.lang.reflect.Method.invokeNative(Native Method)
03-06 01:26:05.479: E/AndroidRuntime(27671):    at java.lang.reflect.Method.invoke(Method.java:507)
03-06 01:26:05.479: E/AndroidRuntime(27671):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
03-06 01:26:05.479: E/AndroidRuntime(27671):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
03-06 01:26:05.479: E/AndroidRuntime(27671):    at dalvik.system.NativeStart.main(Native Method)
03-06 01:26:05.479: E/AndroidRuntime(27671): Caused by: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 5
03-06 01:26:05.479: E/AndroidRuntime(27671):    at android.database.AbstractCursor.checkPosition(AbstractCursor.java)
03-06 01:26:05.479: E/AndroidRuntime(27671):    at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java)
03-06 01:26:05.479: E/AndroidRuntime(27671):    at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java)
03-06 01:26:05.479: E/AndroidRuntime(27671):    at com.ip.scan.LocalSQLite.getImgURL(LocalSQLite.java:57)
03-06 01:26:05.479: E/AndroidRuntime(27671):    at com.ip.scan.MainActivity.onCreate(MainActivity.java:32)
03-06 01:26:05.479: E/AndroidRuntime(27671):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java)
03-06 01:26:05.479: E/AndroidRuntime(27671):    ... 12 more
03-06 01:26:05.549: D/dalvikvm(27671): GC_CONCURRENT freed 220K, 41% free 3334K/5639K, external 0K/0K, paused 3ms+2ms
03-06 01:26:05.549: E/Database(27671): close() was never explicitly called on database '/data/data/com.test.testing/databases/vege.db' 
03-06 01:26:05.549: E/Database(27671): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
03-06 01:26:05.549: E/Database(27671):  at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java)
03-06 01:26:05.549: E/Database(27671):  at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java)
03-06 01:26:05.549: E/Database(27671):  at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java)
03-06 01:26:05.549: E/Database(27671):  at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java)
03-06 01:26:05.549: E/Database(27671):  at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java)
03-06 01:26:05.549: E/Database(27671):  at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java)
03-06 01:26:05.549: E/Database(27671):  at com.ip.scan.LocalSQLite.getImgURL(LocalSQLite.java:53)
03-06 01:26:05.549: E/Database(27671):  at com.ip.scan.MainActivity.onCreate(MainActivity.java:32)
03-06 01:26:05.549: E/Database(27671):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java)
03-06 01:26:05.549: E/Database(27671):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java)
03-06 01:26:05.549: E/Database(27671):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java)
03-06 01:26:05.549: E/Database(27671):  at android.app.ActivityThread.access$1500(ActivityThread.java)
03-06 01:26:05.549: E/Database(27671):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java)
03-06 01:26:05.549: E/Database(27671):  at android.os.Handler.dispatchMessage(Handler.java)
03-06 01:26:05.549: E/Database(27671):  at android.os.Looper.loop(Looper.java)
03-06 01:26:05.549: E/Database(27671):  at android.app.ActivityThread.main(ActivityThread.java)
03-06 01:26:05.549: E/Database(27671):  at java.lang.reflect.Method.invokeNative(Native Method)
03-06 01:26:05.549: E/Database(27671):  at java.lang.reflect.Method.invoke(Method.java:507)
03-06 01:26:05.549: E/Database(27671):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
03-06 01:26:05.549: E/Database(27671):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
03-06 01:26:05.549: E/Database(27671):  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-05-31T00:10:14+00:00Added an answer on May 31, 2026 at 12:10 am

    2 problems, here.

    First, you must start by moving your cursor. moveToFirst or moveToNext is fine.

    Secondly, your index in your array as well as the size of the array is incorrect.

    A proper and current of doing this is as follows:

    mydb = localContext.openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
    Cursor allrows  = mydb.rawQuery("SELECT ImgURL FROM "+  TABLE, null);
    List<String> result = new ArrayList<String>();
    while (allrows.moveToNext()) {
        result.add(allrows.getString(0));
    }
    allrows.close();    
    mydb.close();
    return allrows.toArray(new String[0]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get a Data type mismatch criteria expression error when i try to retrieve
I get this error when I try to use time_ago_in_words : Comparison of String
Why do i get an error when I try using _ instead of using
When we try to create a view within a funcion we get ERROR: there
I get the above error whenever I try and use ActionLink ? I've only
I get the following error when I try to compile an asp.net site using
I get the following error when I try and execute the code down below.
I get the following error when I try to run sample example of Google
When I try to do that I get the error Changed to 64-bit applications
When I try to do a file(' http://somewebsite.com ') i get an error URL

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.