如何在循环中使用游标?

时间:2015-05-02 23:56:26

标签: java android arrays sqlite

问题是我无法加载我的图片,也许我在这里遇到了问题。也许这段代码会出错" java.lang.IndexOutOfBoundsException:索引0无效,大小为0"对不起,我不能描述我的问题T_T。我是android的新手。

  

quest.setImage(Utility.getPhoto(cursor.getBlob(1))); //也许我有   问题在这里

DbHelper.java

private void checkBox4_CheckedChanged(object sender, EventArgs e)
{
    byte[] buffer;
    if (this.checkBox4.Checked)
    {
        this.checkBox4.ForeColor = Color.Green;
        this.checkBox4.Text = "Max Parameters Points on set ON";
        buffer = new byte[] { 0x90, 0xc3, 0, 12 };
        PS3.SetMemory(0x53e088, buffer);
    }
    else
    {
        this.checkBox4.ForeColor = Color.Red;
        this.checkBox4.Text = "Max Parameters Points on set OFF";
        buffer = new byte[] { 0x90, 0x83, 0, 12 };
        PS3.SetMemory(0x53e088, buffer);
    }
}

Question.java

// checkBox4
    // 
    this.checkBox4.AutoSize = true;
    this.checkBox4.Location = new System.Drawing.Point(14, 109);
    this.checkBox4.Name = "checkBox4";
    this.checkBox4.Size = new System.Drawing.Size(165, 17);
    this.checkBox4.TabIndex = 2;
    this.checkBox4.Text = "Max Parameters points on set";
    this.checkBox4.UseVisualStyleBackColor = true;
    this.checkBox4.CheckedChanged += new System.EventHandler(this.checkBox4_CheckedChanged;

Utility.java

public List<Question> getAllQuestions(){
            List<Question> quesList = new ArrayList<Question>();
            String selectQuery = "SELECT * FROM " + TABLE_QUEST + " ORDER BY RANDOM() LIMIT 5";
            dbase=this.getReadableDatabase();
            Cursor cursor = dbase.rawQuery(selectQuery, null);
            // looping through all rows and adding to list
            //==============================================
            if (cursor.moveToFirst()) {
                do {
                    Question quest = new Question();

                    quest.setID(cursor.getInt(0));
                    quest.setImage(Utility.getPhoto(cursor.getBlob(1)));
                    quest.setQUESTION(cursor.getString(2));
                    quest.setANSWER(cursor.getString(3));
                    quest.setOPTA(cursor.getString(4));
                    quest.setOPTB(cursor.getString(5));
                    quest.setOPTC(cursor.getString(6));
                    quesList.add(quest);
                } while (cursor.moveToNext());
            }
            // return quest list
            return quesList;
        }

1 个答案:

答案 0 :(得分:0)

您的查询似乎没有返回您期望的所有7列。

列出查询中的所有实际列名称(总是一个好的做法),因此它会更快地失败并带有更具描述性的消息。

String selectQuery = "SELECT fielName1, fieldName2, "
    + " ..., lastFieldName FROM " + TABLE_QUEST + " ORDER BY RANDOM() LIMIT 5";