傳遞數據我有一個列表視圖從我的數據庫顯示數據的問題。下面是我的顯示方法的代碼。使用ArrayList的<Object>
顯示
public ArrayList<Object> display(String rows) {
ArrayList<Object> rowArray = new ArrayList<Object>();
String[] columns = new String[] { KEY_ROWID, KEY_PACKNAME,
KEY_PACKRENT, KEY_SIMRATE, KEY_NATMINSBUN, KEY_INTMINSBUN,
KEY_INTMINSRATE, KEY_NATSMSBUN,
KEY_NATSMSRATE, KEY_INTSMSBUN, KEY_INTSMSRATE,
KEY_MMSBUN, KEY_MMSRATE, KEY_DATALBUN,
KEY_DATALRATE };
Cursor cursor = ourDatabase.query(DATABASE_TABLE, columns, null, null,
null, null, null);
cursor.moveToFirst();
if (!cursor.isAfterLast())
{
do
{
rowArray.add(cursor.getLong(0));
rowArray.add(cursor.getString(1));
rowArray.add(cursor.getString(2));
rowArray.add(cursor.getString(3));
rowArray.add(cursor.getString(4));
rowArray.add(cursor.getString(5));
rowArray.add(cursor.getString(6));
rowArray.add(cursor.getString(7));
rowArray.add(cursor.getString(8));
rowArray.add(cursor.getString(9));
rowArray.add(cursor.getString(10));
rowArray.add(cursor.getString(11));
rowArray.add(cursor.getString(12));
rowArray.add(cursor.getString(13));
rowArray.add(cursor.getString(14));
} while (cursor.moveToNext());
cursor.close();
}
return rowArray;
}
這是該ArrayList
EtiTariffDatabase test = new EtiTariffDatabase(this);
TextView TV = (TextView) findViewById(R.id.s_etipackname);
TextView TV1 = (TextView) findViewById(R.id.s_etipackrent);
TextView TV2 = (TextView) findViewById(R.id.srentalrate);
TextView TV3 = (TextView) findViewById(R.id.snationalbun);
TextView TV4 = (TextView) findViewById(R.id.seintbun);
TextView TV5 = (TextView) findViewById(R.id.senatsmsbun);
TextView TV6 = (TextView) findViewById(R.id.seintsmsbun);
TextView TV7 = (TextView) findViewById(R.id.sedatalocalbun);
test.open();
try
{
ArrayList<Object> row = test.display(null);
TV.setText((String)row.get(1));
TV1.setText((String)row.get(2));
TV2.setText((String)row.get(3));
TV3.setText((String)row.get(4));
TV4.setText((String)row.get(6));
TV5.setText((String)row.get(8));
TV6.setText((String)row.get(10));
TV7.setText((String)row.get(12));
}
catch (Exception e)
{
Log.e("Retrieve Error", e.toString());
e.printStackTrace();
}
test.close();
}
我捕捉異常是:
04-07 16:48:23.759:E /檢索錯誤(4134):java.lang.IndexOutOfBoundsException:索引1無效,大小爲0 04-07 16:48:23.829:W/System.err的(4134):java.lang.IndexOutOfBoundsException:無效索引1,大小爲0 04-07 16:48:23.829:W/System.err的(4134 ):在java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
我一直試圖玩很久。它起初工作,但我刪除了數據庫,並重新創建它。從那時起沒有任何數據顯示出來,並伴隨着上述錯誤。任何援助將不勝感激。
它顯示我的數組沒有對象。有我的數據庫中的數據因爲我拉我的數據庫文件來檢查這一點。我認爲這與創建我已經完成的對象數組有關。 – 2013-04-07 17:56:03
數組的創建和填充不應該是一個問題,你已經做了正確的。 我認爲查詢有問題,以便遊標返回一組空白的數據。你可以用'Log.d(「cursor」,cursor.getCount()+「」);' – chuky 2013-04-07 18:07:47
發現這個問題。數據庫沒有被創建。固定和繁榮,它一切正常!謝謝! – 2013-04-07 21:00:19