Java – cursorindexoutofboundexception: request index 1, size 1

This is me again. There is a SQLite problem with Android

At present, I get a "cursor index out of boundary exception: request index 1, size 1". However, I have the exception of index - 1, and then insert a cursor Movetofirst(), then I used the index 0 and made cursor moveToNext(); What do I want to do with my code? I want information about a selected item (that's why selectionargs is related to squeryid. What did I do wrong?

Cursor c = a.managedQuery(uri,projection,//projection
            "_ID=?",//selection string
            new String[]{sQueryid},//selection args array of strings
            DepotTableMetaData.DEFAULT_SORT_ORDER); //sort order
    c.moveToFirst();
    c.moveToNext();
    int iqrcode = c.getColumnIndex(ContentProviderMetaData.DepotTableMetaData.ITEM_QRCODE);     
    int iname = c.getColumnIndex(ContentProviderMetaData.DepotTableMetaData.ITEM_NAME);
    int iamount = c.getColumnIndex(ContentProviderMetaData.DepotTableMetaData.ITEM_AMOUNT);
    int iunit = c.getColumnIndex(ContentProviderMetaData.DepotTableMetaData.ITEM_UNIT);
    int ippu = c.getColumnIndex(ContentProviderMetaData.DepotTableMetaData.ITEM_PPU);
    int itotal = c.getColumnIndex(ContentProviderMetaData.DepotTableMetaData.ITEM_TOTAL);
    int icomment = c.getColumnIndex(ContentProviderMetaData.DepotTableMetaData.ITEM_COMMENT);


        //Gather values
        String id = c.getString(Integer.parseInt(queryid.toString()));

        String name = c.getString(iname);
        String amount = c.getString(iamount);
        String unit = c.getString(iunit);
        String ppu = c.getString(ippu);
        String total = c.getString(itotal);
        String comment = c.getString(icomment);
        String qrcode = c.getString(iqrcode);

        String[] info = new String[]{id,name,amount,unit,ppu,total,comment,qrcode};

Solution

Movetofirst takes you to the first (and only) result The next call to movetonext will take you to the second nonexistent result (index 1)

Try to delete c.movetonext();

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>