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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:40:24+00:00 2026-06-17T20:40:24+00:00

01-25 23:51:14.507: WARN/System.err(616): android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 2 I have

  • 0

01-25 23:51:14.507: WARN/System.err(616): android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 2

I have an android application that would use an SQLite database. But when it gets to the select statement it force closes. I have a class file that I use for doing this :

package com.thesis.menubook;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;

public class DBConnect {

        int id = 0;
        public static final String KEY_ROWID = "_id";
        public static final String KEY_IP = "saved_ip_address";
        private static final String TAG = "DBConnect";

        private static final String DATABASE_NAME = "MenuBook";
        private static final String DATABASE_TABLE_1 = "ipaddress";
       //private static final String DATABASE_TABLE_2 = "menudb";
       //private static final String DATABASE_TABLE_3 = "recipelist";
        private static final int DATABASE_VERSION = 1;

        private static final String DATABASE_CREATE_TABLE_1 =
            "CREATE TABLE ipaddress (_id integer primary key autoincrement, " +
                                 "saved_ip_address text not null " +
                                 "); ";
        private static final String DATABASE_CREATE_TABLE_2 =
            "CREATE TABLE menudb (menu_ID varchar primary key not null, " +
                                 "menu_name longtext, " +
                                 "menu_price double null default, " +
                                 "menu_description longtext, " +
                                 "menu_category text, " +
                                 "menu_status text " +
                                 "); ";
        private static final String DATABASE_CREATE_TABLE_3 =
            "CREATE TABLE recipelist (recipe_ID integer primary key not null autoincrement, " +
                                 "menu_ID varchar null default, " +
                                 "stock_ID varchar null default, " +
                                 "recipe_quantity double null defualt " +
                                 ");" ;

        private final Context context;

        private static DatabaseHelper DBHelper;
        private static SQLiteDatabase db;

        public DBConnect(Context ctx)
        {
            this.context = ctx;
            DBHelper = new DatabaseHelper(context);
        }

        public static class DatabaseHelper extends SQLiteOpenHelper
        {
            DatabaseHelper(Context context)
            {
                super(context, DATABASE_NAME, null, DATABASE_VERSION);
            }

            @Override
            public void onCreate(SQLiteDatabase db)
            {
                db.execSQL(DATABASE_CREATE_TABLE_1);
                db.execSQL(DATABASE_CREATE_TABLE_2);
                db.execSQL(DATABASE_CREATE_TABLE_3);
            }

            @Override
            public void onUpgrade(SQLiteDatabase db, int oldVersion,
                                  int newVersion)
            {
                Log.w(TAG, "Upgrading database from version " + oldVersion
                      + " to "
                      + newVersion + ", which will destroy all old data");
                db.execSQL("DROP TABLE IF EXISTS ipaddress");
                db.execSQL("DROP TABLE IF EXISTS menudb");
                db.execSQL("DROP TABLE IF EXISTS recipelist");
                onCreate(db);
            }

        }

        //---opens the database---
        public DBConnect open() throws SQLException
        {
            db = DBHelper.getWritableDatabase();
            return this;
        }

        //---closes the database---
        public void close()
        {
            DBHelper.close();
        }

        //---insert a title into the database---
        public long insertIPAddress(String ipaddress)
        {
            ContentValues initialValues = new ContentValues();
            initialValues.put(KEY_IP, ipaddress);
            return db.insert(DATABASE_TABLE_1, null, initialValues);
        }

        public String getIP()
        {
            String retrievedIP;

            String query = "SELECT saved_ip_address FROM ipaddress WHERE _id = (SELECT MAX(_id) FROM ipaddress)";
            Cursor cursor = db.rawQuery(query, null);
            retrievedIP= cursor.getString(cursor.getColumnIndex("saved_ip_address"));
            cursor.close();
            return retrievedIP;
        }

        public List<ColumnValue[]> select(final String query)
        {
            List<ColumnValue[]> result = null;
            Cursor cursor = db.rawQuery(query, null);

            if (cursor.moveToFirst())
            {
                result = new ArrayList<ColumnValue[]>();

                do
                {
                    int columns = cursor.getColumnCount();
                    ColumnValue[] cvarray = new ColumnValue[columns];

                    for (int i=0; i<columns; i++)
                    {
                        String key = cursor.getColumnName(i);
                        String value = cursor.getString(i);
                        ColumnValue cv = new ColumnValue(key, value);
                        cvarray[i] = cv;
                    }

                    result.add(cvarray);
                }
                while (cursor.moveToNext());
            }

            cursor.close();

            return result;
        }

        public class ColumnValue
        {
            public String column, value;

            public ColumnValue(String c, String v)
            {
                column = c; value = v;
            }
        }


}

I think it is on the getID() clause but I can’t see anything wrong with it nor my SELECT statetment. What I am trying to do here is to get the value of the saved_ip_address which is at the very bottom of the ipaddress table.

Here is my LogCat where the start of error is bolded out.

Thank You

01-25 23:51:14.507: WARN/System.err(616): android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 2

01-25 23:51:14.568: WARN/System.err(616):     at android.database.AbstractCursor.checkPosition(AbstractCursor.java:421)
01-25 23:51:14.568: WARN/System.err(616):     at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:117)
01-25 23:51:14.578: WARN/System.err(616):     at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:31)
01-25 23:51:14.590: WARN/System.err(616):     at com.thesis.menubook.DBConnect.getIP(DBConnect.java:113)
01-25 23:51:14.590: WARN/System.err(616):     at com.thesis.menubook.ChooseTable$GetTableDetails$1.run(ChooseTable.java:103)
01-25 23:51:14.622: WARN/System.err(616):     at android.os.Handler.handleCallback(Handler.java:587)
01-25 23:51:14.622: WARN/System.err(616):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-25 23:51:14.622: WARN/System.err(616):     at android.os.Looper.loop(Looper.java:132)
01-25 23:51:14.648: WARN/System.err(616):     at android.app.ActivityThread.main(ActivityThread.java:4025)
01-25 23:51:14.688: WARN/System.err(616):     at java.lang.reflect.Method.invokeNative(Native Method)
01-25 23:51:14.688: WARN/System.err(616):     at java.lang.reflect.Method.invoke(Method.java:491)
01-25 23:51:14.688: WARN/System.err(616):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
01-25 23:51:14.688: WARN/System.err(616):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
01-25 23:51:14.688: WARN/System.err(616):     at dalvik.system.NativeStart.main(Native Method)
01-25 23:51:14.998: DEBUG/AndroidRuntime(616): Shutting down VM
01-25 23:51:15.008: WARN/dalvikvm(616): threadid=1: thread exiting with uncaught exception (group=0x40014760)
01-25 23:51:15.138: ERROR/AndroidRuntime(616): FATAL EXCEPTION: main
01-25 23:51:15.138: ERROR/AndroidRuntime(616): java.lang.IllegalArgumentException: Host name may not be null
01-25 23:51:15.138: ERROR/AndroidRuntime(616):     at org.apache.http.HttpHost.<init>(HttpHost.java:83)
01-25 23:51:15.138: ERROR/AndroidRuntime(616):     at org.apache.http.impl.client.AbstractHttpClient.determineTarget(AbstractHttpClient.java:497)
01-25 23:51:15.138: ERROR/AndroidRuntime(616):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
01-25 23:51:15.138: ERROR/AndroidRuntime(616):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
01-25 23:51:15.138: ERROR/AndroidRuntime(616):     at com.thesis.menubook.JSONParser.makeHttpRequest(JSONParser.java:62)
01-25 23:51:15.138: ERROR/AndroidRuntime(616):     at com.thesis.menubook.ChooseTable$GetTableDetails$1.run(ChooseTable.java:119)
01-25 23:51:15.138: ERROR/AndroidRuntime(616):     at android.os.Handler.handleCallback(Handler.java:587)
01-25 23:51:15.138: ERROR/AndroidRuntime(616):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-25 23:51:15.138: ERROR/AndroidRuntime(616):     at android.os.Looper.loop(Looper.java:132)
01-25 23:51:15.138: ERROR/AndroidRuntime(616):     at android.app.ActivityThread.main(ActivityThread.java:4025)
01-25 23:51:15.138: ERROR/AndroidRuntime(616):     at java.lang.reflect.Method.invokeNative(Native Method)
01-25 23:51:15.138: ERROR/AndroidRuntime(616):     at java.lang.reflect.Method.invoke(Method.java:491)
01-25 23:51:15.138: ERROR/AndroidRuntime(616):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
01-25 23:51:15.138: ERROR/AndroidRuntime(616):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
01-25 23:51:15.138: ERROR/AndroidRuntime(616):     at dalvik.system.NativeStart.main(Native Method)
01-25 23:51:15.328: WARN/ActivityManager(83):   Force finishing activity com.thesis.menubook/.ChooseTable
01-25 23:51:15.958: WARN/ActivityManager(83): Activity pause timeout for ActivityRecord{408b4228 com.thesis.menubook/.ChooseTable}
01-25 23:51:20.048: INFO/Process(616): Sending signal. PID: 616 SIG: 9
01-25 23:51:21.068: INFO/ActivityManager(83): Process com.thesis.menubook (pid 616) has died.
01-25 23:51:21.089: ERROR/InputDispatcher(83): channel '408408d0 com.thesis.menubook/com.thesis.menubook.IPAddress (server)' ~ Consumer closed input channel or an error occurred.  events=0x8
01-25 23:51:21.098: ERROR/InputDispatcher(83): channel '408408d0 com.thesis.menubook/com.thesis.menubook.IPAddress (server)' ~ Channel is unrecoverably broken and will be disposed!
01-25 23:51:21.768: INFO/WindowManager(83): WIN DEATH: Window{408408d0 com.thesis.menubook/com.thesis.menubook.IPAddress paused=false}
01-25 23:51:22.108: INFO/WindowManager(83): WIN DEATH: Window{407b66d8 com.thesis.menubook/com.thesis.menubook.ChooseTable paused=false}
01-25 23:51:22.246: INFO/WindowManager(83): WIN DEATH: Window{4097d668 com.thesis.menubook/com.thesis.menubook.ChooseTable paused=false}
01-25 23:51:22.358: INFO/WindowManager(83): WINDOW DIED Window{408408d0 com.thesis.menubook/com.thesis.menubook.IPAddress paused=false}
01-25 23:51:22.449: ERROR/InputDispatcher(83): Received spurious receive callback for unknown input channel.  fd=188, events=0x8
01-25 23:51:22.449: ERROR/InputDispatcher(83): Received spurious receive callback for unknown input channel.  fd=190, events=0x8
01-25 23:51:23.468: DEBUG/dalvikvm(147): GC_EXPLICIT freed <1K, 4% free 12942K/13383K, paused 285ms+19ms
01-25 23:51:23.858: WARN/InputManagerService(83): Got RemoteException sending setActive(false) notification to pid 616 uid 10004
01-25 23:52:15.278: DEBUG/SntpClient(83): request time failed: java.net.SocketException: Address family not supported by protocol
01-25 23:57:15.589: DEBUG/SntpClient(83): request time failed: java.net.SocketException: Address family not supported by protocol
  • 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-17T20:40:26+00:00Added an answer on June 17, 2026 at 8:40 pm

    after getting a Cursor object you need to advance to the first row…

     cursor.moveToFirst();
    

    prior to fetching from the cursor. also you’ll need to check if indeed there are any rows present in the cursor.

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

Sidebar

Related Questions

I have an .apk application for android which has been compiled and packed with
I am developing a map application in android i have made maplocation class to
I have the following layout: <Button android:id=@+id/MyButton android:layout_width=fill_parent android:layout_height=wrap_content android:text=@string/Hello android:clickable=true android:onClick=Foo /> And
I am getting nullpointerexception in Application subclass. There I want a context that should
I published my application to android market. I got error in my home page.
I have a cordova 2.0 app for android. I use the FileTransfer Plugin, to
I have 507 tables with (pattern = human). Inside each table there are a
I have an issue when I sort desc/asc on a column in a database
http://chart.apis.google.com/chart?cht=lc&chs=600x400&chd=t:171,811,629,507,460,390,434,379,329,312,368,329,329,329,352,330,299,323,340,325,329,1895,1047,736,617,684,620,515 If you go there on your browser, you'll notice that you see a
I have the dataset: top100_repository_name month monthly_increase monthly_begin_at monthly_end_with Bukkit 2012-03 9 431 440

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.