我一直在尋找/做不同的需要低於該代碼的:問題與陣列經由環狀的查詢生成導致
public String[] getData() {
String[] columns = new String[]{ app_name, app_location, app_dateTime};
Cursor c = myDatabase.query(app_table, columns, null, null, null, null, null);
int iName = c.getColumnIndex(app_name);
int iLoc = c.getColumnIndex(app_location);
int iDate = c.getColumnIndex(app_dateTime);
String[] appointments = new String[c.getColumnCount()];
int j = 0;
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
appointments[j] = " Appointment Name: " + c.getString(iName) + " \n Location: " + c.getString(iLoc) + " \n Date: " + c.getString(iDate) + " \n\n ";
j++;
}
return appointments;
}
}
基本上這個碼的目標是讓我的查詢結果被饋送到一個數組和然後通過代碼的「返回約會」部分在另一個類的ListView中訪問。出於某種原因,我的代碼似乎不工作,我不能完全把我的手指放在它上面,我嘗試過在循環中循環我已經試着淡化代碼,然後展開我可以工作的東西,但沒有一個是給予的我一個解決方案。
我的歉意,我沒有提到,我也試過改變 String []約會=新字符串[c.getCount()]; 至: String []約會=新字符串[99]; 爲了試驗和錯誤。我相信這個錯誤是在for循環本身的某個地方,但我無法找到它。 – 2012-03-14 12:06:34