Not sure how to convert a Cursor to this method's return type (com.example.cameradiary.SecondActivity.ImageInfo). List<SecondActivity.ImageInfo> getALLUsers(); ^
时间: 2023-12-10 12:40:45 浏览: 109
It seems like you are trying to return a List of ImageInfo objects from the method `getALLUsers()` in the `SecondActivity` class. However, you are getting an error related to converting a Cursor object to the return type.
To fix this error, you need to fetch the data from the Cursor object and convert it into a List of ImageInfo objects. Here's an example of how you can do this:
```
public List<ImageInfo> getALLUsers() {
SQLiteDatabase db = this.getReadableDatabase();
List<ImageInfo> imageInfoList = new ArrayList<>();
String[] projection = {...}; // Define the columns you want to fetch
String sortOrder = "..."; // Define the sort order of the results
Cursor cursor = db.query(
TABLE_NAME,
projection,
null,
null,
null,
null,
sortOrder
);
while (cursor.moveToNext()) {
// Extract the data from the cursor and create a new ImageInfo object
ImageInfo imageInfo = new ImageInfo();
imageInfo.setId(cursor.getInt(cursor.getColumnIndexOrThrow(COLUMN_ID)));
imageInfo.setName(cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_NAME)));
imageInfo.setPath(cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_PATH)));
// Add the ImageInfo object to the list
imageInfoList.add(imageInfo);
}
cursor.close();
return imageInfoList;
}
```
In this example, we are using the `query()` method to fetch all rows from the database table and store them in a Cursor object. Then, we iterate over the cursor using a while loop and extract the data from each row to create a new ImageInfo object. Finally, we add the ImageInfo object to a List and return the list.
阅读全文