Here is my 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)
The LogCat refers to this line of code01-15 22:13:08.277: ERROR/AndroidRuntime(28747): at com.mohit.geo2do.adapters.TasksAdapter.bindView(TasksAdapter.java:60)
. Here is my task adapter's bindView
method:
@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");
}
I have verified 100% that the column does exist. What could be the problem?
UPDATE:
The cursor is from a bindView method, so I have not created the query for the cursor myself. I recreated the database and now I get this error: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 an开发者_开发知识库droid.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)
I have verified that the column index is -1:
01-16 09:46:39.434: VERBOSE/TasksAdapter(32563): The index is -1
And that the due_date column exists:
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
Ensure that the query that generated your Cursor includes the field which Tasks.DUE_DATE refers to. If it does not, getColumnIndex will return -1. You can also use getColumnIndexOrThrow, which allows you to catch an IllegalArgumentException.
精彩评论