0
我在查詢我的SQLite Database
從WidgetRemoteService
。數據庫已經正確存儲。我無法從數據庫檢索url
字符串。無法從CursorWindow SQLite讀取第0行第5列Android
這就是我對我的logcat
E/UncaughtException: java.lang.IllegalStateException: Couldn't read row 0, col 5 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.database.CursorWindow.nativeGetString(Native Method)
at android.database.CursorWindow.getString(CursorWindow.java:438)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
at android.database.CursorWrapper.getString(CursorWrapper.java:137)
at io.wyntr.peepster.widget.DetailWidgetRemoteService$1.getViewAt(DetailWidgetRemoteService.java:101)
at android.widget.RemoteViewsService$RemoteViewsFactoryAdapter.getViewAt(RemoteViewsService.java:164)
at com.android.internal.widget.IRemoteViewsFactory$Stub.onTransact(IRemoteViewsFactory.java:85)
at android.os.Binder.execTransact(Binder.java:453)
這是我在WidgetIntentService
private static final String[] FEEDS_COLUMNS = {
FeedsContract.FeedsEntry.TABLE_NAME + "." + FeedsContract.FeedsEntry._ID,
FeedsContract.FeedsEntry.COLUMN_USER,
FeedsContract.FeedsEntry.COLUMN_POST_KEY,
FeedsContract.FeedsEntry.COLUMN_THUMB,
};
static final int INDEX_FEED_ID = 0;
static final int INDEX_USER_NAME = 1;
static final int INDEX_FEEDS_THUMB = 4;
static final int INDEX_FEED_KEY = 5;
@Override
public void onDataSetChanged() {
if (data != null) {
data.close();
}
final long identityToken = Binder.clearCallingIdentity();
data = getContentResolver().query(FeedsContract.FeedsEntry.CONTENT_URI,
FEEDS_COLUMNS,
null,
null,
null);
Binder.restoreCallingIdentity(identityToken);
}
@Override
public RemoteViews getViewAt(int position) {
if (position == AdapterView.INVALID_POSITION ||
data == null || !data.moveToPosition(position)) {
return null;
}
RemoteViews views = new RemoteViews(getPackageName(),
R.layout.widget_items);
String thumbId = data.getString(INDEX_FEEDS_THUMB);
Bitmap feedsImage = null;
try {
feedsImage = Glide.with(DetailWidgetRemoteService.this)
.load(thumbId)
.asBitmap()
.error(R.drawable.person_placeholder)
.into(150, 150).get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
查詢這是我的合同類
public static final class FeedsEntry implements BaseColumns {
public static final Uri CONTENT_URI =
BASE_CONTENT_URI.buildUpon().appendPath(PATH_FEEDS).build();
public static final String CONTENT_TYPE =
ContentResolver.CURSOR_DIR_BASE_TYPE + "/" + CONTENT_AUTHORITY + "/" + PATH_FEEDS;
public static final String CONTENT_ITEM_TYPE =
ContentResolver.CURSOR_ITEM_BASE_TYPE + "/" + CONTENT_AUTHORITY + "/" + PATH_FEEDS;
public static final String TABLE_NAME = "feeds";
public static final String COLUMN_USER = "username";
public static final String COLUMN_VIDEO = "video";
public static final String COLUMN_TIME_STAMP = "timestamp";
public static final String COLUMN_THUMB = "thumb";
public static final String COLUMN_POST_KEY = "key";
public static final String COLUMN_USER_PROFILE = "profile";
@pskink共7行 – Contextioner
@pskink你可以檢查我現在已經上傳的logcat – Contextioner