Android 通过循环查询结果生成数组时出现问题

Android 通过循环查询结果生成数组时出现问题,android,arrays,sqlite,loops,cursor,Android,Arrays,Sqlite,Loops,Cursor,我一直在寻找/执行以下代码的不同操作: 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

我一直在寻找/执行以下代码的不同操作:

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[] appointments = new String[c.getColumnCount()];
你需要使用

String[] appointments = new String[c.getCount()];

getColumnCount()
返回列数(通常是3个-名称、位置、日期时间-),您需要那里的行数。

我道歉并感谢提交答案的人,我已经找出了问题所在,这是在我的另一个java类中。上面列出的循环功能齐全,因此,如果有人需要找到一段代码来执行上面的要求,请不要再看了。

抱歉,我没有提到我也尝试过更改字符串[]约会=新字符串[c.getCount()];收件人:字符串[]约会=新字符串[99];为了试验和错误。我相信错误在for循环本身的某些地方,但我就是找不到它。