gpt4 book ai didi

java - 非法状态异常 : get field slot from row 0 col -1 failed

转载 作者:IT王子 更新时间:2023-10-29 06:22:24 25 4
gpt4 key购买 nike

这是我的 LogCat:

01-15 22:13:08.277: ERROR/AndroidRuntime(28747): java.lang.IllegalStateException: get field slot from row 0 col -1 failed
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.database.CursorWindow.getLong_native(Native Method)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.database.CursorWindow.getLong(CursorWindow.java:414)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:108)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.database.CursorWrapper.getLong(CursorWrapper.java:127)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at com.mohit.geo2do.adapters.TasksAdapter.bindView(TasksAdapter.java:60)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.widget.CursorAdapter.getView(CursorAdapter.java:186)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.widget.AbsListView.obtainView(AbsListView.java:2818)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.widget.ListView.measureHeightOfChildren(ListView.java:1218)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.widget.ListView.onMeasure(ListView.java:1131)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.view.View.measure(View.java:8039)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.widget.RelativeLayout.measureChild(RelativeLayout.java:554)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:377)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.view.View.measure(View.java:8039)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3025)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.view.View.measure(View.java:8039)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.widget.LinearLayout.measureVertical(LinearLayout.java:464)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.widget.LinearLayout.onMeasure(LinearLayout.java:278)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.view.View.measure(View.java:8039)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3025)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.view.View.measure(View.java:8039)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.view.ViewRoot.performTraversals(ViewRoot.java:779)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.view.ViewRoot.handleMessage(ViewRoot.java:1658)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.os.Handler.dispatchMessage(Handler.java:99)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.os.Looper.loop(Looper.java:123)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at android.app.ActivityThread.main(ActivityThread.java:4363)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at java.lang.reflect.Method.invokeNative(Native Method)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at java.lang.reflect.Method.invoke(Method.java:521)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at dalvik.system.NativeStart.main(Native Method)

LogCat 指的是这行代码01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at com.mohit.geo2do.adapters.TasksAdapter.bindView(TasksAdapter.java:60)。这是我的任务适配器的 bindView 方法:

@Override
public void bindView(View view, Context context, Cursor cursor) {
CheckBox checkbox = (CheckBox)view.findViewById(R.id.completed);
TextView due_date = (TextView)view.findViewById(R.id.due_date);

String title = cursor.getString(cursor.getColumnIndex(Tasks.TITLE));
boolean completed = Util.intToBool(cursor.getInt(cursor.getColumnIndex(Tasks.COMPLETED)));

SimpleDateFormat format = new SimpleDateFormat("EEEEEE, MMM dd yyyy hh:mm aa");
long unixTime = Calendar.getInstance().getTimeInMillis();
if (cursor.getLong(cursor.getColumnIndex(Tasks.DUE_DATE)) > 0) {
Log.v("TasksAdapter", "Unix time is " + unixTime);
unixTime = cursor.getLong(cursor.getColumnIndex(Tasks.DUE_DATE));
Calendar due = Util.timestampToDate(unixTime);

due_date.setText(format.format(due.getTime()));
}
checkbox.setText(title);
checkbox.setChecked(completed);
due_date.setText("No Deadline");
}

我已 100% 验证该列确实存在。可能是什么问题呢?

更新:
游标来自 bindView 方法,所以我自己没有为游标创建查询。我重新创建了数据库,但现在出现此错误:

01-16 09:46:39.459: ERROR/AndroidRuntime(32563): java.lang.IllegalArgumentException: column 'due_date' does not exist
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.database.CursorWrapper.getColumnIndexOrThrow(CursorWrapper.java:99)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at com.mohit.geo2do.adapters.TasksAdapter.bindView(TasksAdapter.java:64)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.widget.CursorAdapter.getView(CursorAdapter.java:186)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.widget.AbsListView.obtainView(AbsListView.java:2818)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.widget.ListView.measureHeightOfChildren(ListView.java:1218)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.widget.ListView.onMeasure(ListView.java:1131)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.view.View.measure(View.java:8039)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.widget.RelativeLayout.measureChild(RelativeLayout.java:554)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:377)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.view.View.measure(View.java:8039)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3025)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.view.View.measure(View.java:8039)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.widget.LinearLayout.measureVertical(LinearLayout.java:464)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.widget.LinearLayout.onMeasure(LinearLayout.java:278)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.view.View.measure(View.java:8039)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3025)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.view.View.measure(View.java:8039)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.view.ViewRoot.performTraversals(ViewRoot.java:779)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.view.ViewRoot.handleMessage(ViewRoot.java:1658)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.os.Handler.dispatchMessage(Handler.java:99)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.os.Looper.loop(Looper.java:123)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at android.app.ActivityThread.main(ActivityThread.java:4363)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at java.lang.reflect.Method.invokeNative(Native Method)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at java.lang.reflect.Method.invoke(Method.java:521)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
01-16 09:46:39.459: ERROR/AndroidRuntime(32563): at dalvik.system.NativeStart.main(Native Method)

我已验证列索引为 -1:

01-16 09:46:39.434: VERBOSE/TasksAdapter(32563): The index is -1

并且存在 due_date 列:

01-16 09:46:29.839: VERBOSE/TasksProvider(32563): Creating database...
01-16 09:46:29.839: VERBOSE/TasksProvider(32563): _id
01-16 09:46:29.839: VERBOSE/TasksProvider(32563): title
01-16 09:46:29.839: VERBOSE/TasksProvider(32563): completed
01-16 09:46:29.839: VERBOSE/TasksProvider(32563): due_date
01-16 09:46:29.839: VERBOSE/TasksProvider(32563): notes
01-16 09:46:29.839: VERBOSE/TasksProvider(32563): importance

最佳答案

确保生成 Cursor 的查询包含 Tasks.DUE_DATE 引用的字段。如果不是,getColumnIndex 将返回 -1。您还可以使用 getColumnIndexOrThrow,它允许您捕获 IllegalArgumentException。

关于java - 非法状态异常 : get field slot from row 0 col -1 failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4703634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com