错误显示光标超出范围

时间:2015-05-14 09:04:08

标签: android sqlite

我将特定数据显示到listview中,即使我的模拟器变成空白,它也会显示任何内容.... 查询为..

SQLiteDatabase sd = db.getReadableDatabase();
        String select = "SELECT * FROM pending_dues_table WHERE _pending_dues_id ="+i;
        cr = sd.rawQuery(select, null);
         if (cr != null) {
                //cr.moveToFirst();
             int ii;
             ii=cr.getColumnIndex("pending_dues_notice");
                while (cr.moveToLast()){                    
                    namelist.add(cr.getString(ii));
                    //studentno.add(cursor.getString(1));                   
                }
            }      
        ArrayList<String>combimelist=new ArrayList<String>();
        for(int j = 0; j<namelist.size();j++){
            combimelist.add(namelist.get(j));
        }
        adapter = new ArrayAdapter<String>(StudentDues.this,R.layout.student_due, combimelist);

和locat显示错误为..

05-25 03:33:56.225: E/AndroidRuntime(5134): FATAL EXCEPTION: main
05-25 03:33:56.225: E/AndroidRuntime(5134): java.lang.OutOfMemoryError: [memory exhausted]
05-25 03:33:56.225: E/AndroidRuntime(5134):     at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:1)

你的logcat说

    CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
       ......
    at com.example.mytryapp.TeacherStudent$1.onClick(TeacherStudent.java:57)

所以我认为你的问题是野兔

if (get_rollno.equals(CR.getString(0))) 
{
   loginstatus = true; NAME=CR.getString(0);
} 

我的建议只是在调用之前检查你必须有一些数据。 试着这样做希望它有效

if(cursor.getCount() > 0){
// get values from cursor here
    if (get_rollno.equals(CR.getString(0))) 
    {
       loginstatus = true; NAME=CR.getString(0);
    }
}

或者有更好的方法

尝试

Cursor cursor = //query here
while (cursor.moveToNext()) {
    // retrieve  values from the cursor
}

如果有任何问题......请评论