0

我在将搜索到的数据存储到我的列表时遇到问题。谁能检查我的存储数组和数组列表的构造。谢谢。

Tag CursorWinow: bad request for field slot 0,12. numRows = 49, numColumns =12

public List<HashMap<String, String>> getAllDataFromTable(String tableName) {//, String[] ColumnList
        List<HashMap<String, String>> TableDataCollection;
        TableDataCollection = new ArrayList<HashMap<String, String>>();

        String selectQuery = "SELECT  * FROM " +tableName;
        SQLiteDatabase database = this.getWritableDatabase();
        Cursor cursor = database.rawQuery(selectQuery, null);
        String ColumnCollection[];

        int totalRecord=cursor.getColumnCount();
        if(tableName=="tbl_account_codes")
        {
        if (cursor.moveToFirst()) {
          do {
              int i=cursor.getColumnNames().length;
              ColumnCollection=new String[i];

              String MainColumnCollection[];
              MainColumnCollection=new String[i];
             String[] MyColumn= ColumnCollection=cursor.getColumnNames();//column
              for(int a=0;a<=i;a++) 
              {

                  MainColumnCollection[a]=(cursor.getString(a).toString());//= ColumnCollection[a]
                  String z="wala lang";
                  String x="wala lang";

                  //String AssignCol= MyColumn[a];
              }

               TableDataCollection.add((HashMap<String, String>) Arrays.asList(MainColumnCollection));
               String c="wala lang";
              } while (cursor.moveToNext());
            }
            return TableDataCollection;
            }
TableDataCollection.add((HashMap<String, String>) Arrays.asList(MainColumnCollection));


我在这条线上有问题。谢谢

4

1 回答 1

1

尝试以下行

MainColumnCollection[a]=(cursor.getString(cursor.getColumnIndex("YOUR_COLUMN_NAME")));

代替

MainColumnCollection[a]=(cursor.getString(a).toString());

编辑

=从你的循环中删除for并像这样改变

for(int a=0;a<i;a++) 
于 2013-09-27T06:32:23.603 回答