开发者

problem in getting particular item from database in android application

I am develop开发者_Go百科ing an android application in which i have to show data from database.I have created the database and now i am showing the database in the listview.Below is the crash that i am unable to resolve

09-08 01:20:45.651: ERROR/AndroidRuntime(16459): Caused by: android.database.CursorIndexOutOfBoundsException: Index 114 requested, with a size of 114 09-08 01:20:45.651: ERROR/AndroidRuntime(16459): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580) 09-08 01:20:45.651: ERROR/AndroidRuntime(16459): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214) 09-08 01:20:45.651: ERROR/AndroidRuntime(16459): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41) 09-08 01:20:45.651: ERROR/AndroidRuntime(16459): at com.redorange.database.MessageDbAdapter.GetSeedDetails(MessageDbAdapter.java:360) 09-08 01:20:45.651: ERROR/AndroidRuntime(16459): at com.redorange.headshop.CustomAdapter.onCreate(CustomAdapter.java:36) 09-08 01:20:45.651: ERROR/AndroidRuntime(16459): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 09-08 01:20:45.651: ERROR/AndroidRuntime(16459): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586) 09-08 01:20:45.651: ERROR/AndroidRuntime(16459): ... 11 more

Can anyone help me,,,

Thanks in advance Tushar


In GetSeedDetails method use something like this code:

public ArrayList<GetDataBaseValues> GetSeedDetails()throws SQLException
{
    ArrayList<GetDataBaseValues> seedRecordsList = new  ArrayList<GetDataBaseValues>();
    GetDataBaseValues getDatabaseVariables;
    Cursor mCursor = mDb.query("headshop", 
            new String[] {"_id","name","grade","description"
            }, null, null, null, null, null);

    mCursor.moveToFirst();
    while(mCursor.isAfterLast() == false)
    {
        getDatabaseVariables = new GetDataBaseValues();
        String name = mCursor.getString(mCursor.getColumnIndex("name"));
        getDatabaseVariables.setName(name);
        String grade = mCursor.getString(mCursor.getColumnIndex("grade"));
        getDatabaseVariables.setGrade(grade);
        String desc = mCursor.getString(mCursor.getColumnIndex("description"));
        getDatabaseVariables.setDesc(desc);
        seedRecordsList.add(getDatabaseVariables);
        mCursor.moveToNext();
    }
    mCursor.close();
    return seedRecordsList;
}


Looks like you're trying to access an item from your database at a position that isn't valid

android.database.CursorIndexOutOfBoundsException: Index 114

You're probably trying to access an item that doesn't exist within the dataset, either a row beyond the end of the returned rows or else an item within the row that doesn't exist.

Show us your CustomAdapter code (with line numbers if possible!)

EDIT

Your function GetSeedDetails is wrong. You're moving logic is incorrect causing you to exceed the limits of the cursor. Use only the moveToNext call in the while condition and you'll iterate over the data values. Also dont forget to close the cursor when you're done!

public ArrayList<GetDataBaseValues> GetSeedDetails()throws SQLException
{
    ArrayList<GetDataBaseValues> seedRecordsList = new  ArrayList<GetDataBaseValues>();
    GetDataBaseValues getDatabaseVariables; 
    Cursor mCursor = mDb.query("headshop", new String[] {"_id","name","grade","description"
              }, null, null, null, null, null);


    while(mCursor.moveToNext())
    {  
         getDatabaseVariables = new GetDataBaseValues();
         getDatabaseVariables.setName(mCursor.getString(01).toString());
         Log.e("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", mCursor.getString(1).toString());
         getDatabaseVariables.setGrade(mCursor.getString(0).toString());
         Log.e("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", mCursor.getString(2).toString());
         getDatabaseVariables.setDesc(mCursor.getString(0).toString());
         Log.e("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", mCursor.getString(3).toString());
         seedRecordsList.add(getDatabaseVariables);

  }
  mCursor.close();
  return seedRecordsList;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜