我正在尝试创建大小动态的数组列表,添加元素并在完成时遍历它们。目前我的代码是:
String activities = "SELECT DISTINCT phoneactivity from ContextTable030313";
ArrayList<String> myActivities = new ArrayList();
Cursor cursor2 = db.rawQuery(activities, null);
// looping through all rows and adding to list
if (cursor2.moveToFirst()) {
do {
myActivities.add(cursor.getString(cursor2.getColumnIndex("ts")));
} while (cursor2.moveToNext());
}
然而它无法在 do 循环中运行。我相信我声明不正确,我收到以下警告:
- ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized
- Avoid object allocations during draw/layout operations (preallocate and reuse instead)
- Type safety: The expression of type ArrayList needs unchecked conversion to conform to
ArrayList<String>
但我不明白为什么这不起作用。