我在将搜索到的数据存储到列表时遇到问题。任何人都可以检查我的存储阵列和数组列表的构造。感谢。
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));
我在这条线上遇到了问题。感谢
答案 0 :(得分:1)
尝试以下行
MainColumnCollection[a]=(cursor.getString(cursor.getColumnIndex("YOUR_COLUMN_NAME")));
而不是
MainColumnCollection[a]=(cursor.getString(a).toString());
修改强>
从您的=
循环中移除for
并按此更改
for(int a=0;a<i;a++)