我设法解决了我的最后一个问题,但现在我遇到了这个问题:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.eazymocky/com.example.eazymocky.MainActivity}: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
但我的cursors
已初始化,并且在尝试填充控件时似乎会显示:
我的代码如下:
public LocationEntity getLocationEntity(long locId) {
String query = "SELECT * FROM " + dbHelper.tableLocations + " WHERE "
+ idColumn + " = " + locId;
Log.e(LOG, query);
Cursor cursor = database.rawQuery(query, null);
if (cursor != null) {
cursor.moveToFirst();
}
LocationEntity location = new LocationEntity();
location.setLocationId(cursor.getInt(cursor.getColumnIndex(idColumn)));
location.setLocationName(cursor.getString(cursor
.getColumnIndex(locationName)));
location.setLocationIcon(cursor.getString(cursor
.getColumnIndex(locationIcon)));
location.setLocationAddress(cursor.getString(cursor
.getColumnIndex(locationAddress)));
location.setLocationCity(cursor.getString(cursor
.getColumnIndex(locationCity)));
location.setLocationZIP(cursor.getString(cursor
.getColumnIndex(locationZIP)));
location.setLocationCountry(cursor.getString(cursor
.getColumnIndex(locationCountry)));
location.setFavoriteFlag(cursor.getInt(cursor
.getColumnIndex(locationIsFavorite)));
return location;
}
您可以提供的任何帮助都非常受欢迎! :)