我实现了一个CursorTreeAdapter,并使用它来从包含有关天数的信息的sqlite数据库中获取数据。现在我希望将那些日子分组为几个月。为此,我实现了一个Cursor返回Months + Years列表,以及一个子光标,用于检索应该在该组中的天数。
我的组光标似乎运行得很好,我得到mm.YYYY作为组头,至少在一些较旧的设备上,在较新的设备上测试它并且在那里崩溃没有明显的原因。由于它不包含我的项目中的任何代码,我不确定如何解决这个问题。
12-12 12:54:38.671: E/AndroidRuntime(11329): FATAL EXCEPTION: main
12-12 12:54:38.671: E/AndroidRuntime(11329): java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.database.CursorWindow.nativeGetLong(Native Method)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.database.CursorWindow.getLong(CursorWindow.java:507)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:75)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.widget.CursorTreeAdapter$MyCursorHelper.getId(CursorTreeAdapter.java:436)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.widget.CursorTreeAdapter.getGroupId(CursorTreeAdapter.java:191)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.widget.ExpandableListConnector.getItemId(ExpandableListConnector.java:422)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.widget.AbsListView.obtainView(AbsListView.java:2180)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.widget.ListView.measureHeightOfChildren(ListView.java:1246)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.widget.ListView.onMeasure(ListView.java:1158)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.view.View.measure(View.java:15525)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.view.View.measure(View.java:15525)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.view.View.measure(View.java:15525)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1447)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.view.View.measure(View.java:15525)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.view.View.measure(View.java:15525)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.view.View.measure(View.java:15525)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
12-12 12:54:38.671: E/AndroidRuntime(11329): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2438)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.view.View.measure(View.java:15525)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.view.Choreographer.doFrame(Choreographer.java:532)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.os.Handler.handleCallback(Handler.java:725)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.os.Handler.dispatchMessage(Handler.java:92)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.os.Looper.loop(Looper.java:137)
12-12 12:54:38.671: E/AndroidRuntime(11329): at android.app.ActivityThread.main(ActivityThread.java:5227)
12-12 12:54:38.671: E/AndroidRuntime(11329): at java.lang.reflect.Method.invokeNative(Native Method)
12-12 12:54:38.671: E/AndroidRuntime(11329): at java.lang.reflect.Method.invoke(Method.java:511)
12-12 12:54:38.671: E/AndroidRuntime(11329): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
12-12 12:54:38.671: E/AndroidRuntime(11329): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
12-12 12:54:38.671: E/AndroidRuntime(11329): at dalvik.system.NativeStart.main(Native Method)
无论如何,在较旧的设备上,标题按预期显示。但是在单击标题时会抛出类似的堆栈跟踪。所以我的猜测是,较新的手机试图为我扩展群组,而不必实际点击它。
01-03 21:48:06.656: E/CursorWindow(16844): Bad request for field slot 0,-1. numRows = 1, numColumns = 2
01-03 21:48:06.656: W/dalvikvm(16844): threadid=1: thread exiting with uncaught exception (group=0x40018578)
01-03 21:48:06.664: E/AndroidRuntime(16844): FATAL EXCEPTION: main
01-03 21:48:06.664: E/AndroidRuntime(16844): java.lang.IllegalStateException: get field slot from row 0 col -1 failed
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.database.CursorWindow.getLong_native(Native Method)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.database.CursorWindow.getLong(CursorWindow.java:412)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:108)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.widget.CursorTreeAdapter$MyCursorHelper.getId(CursorTreeAdapter.java:437)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.widget.CursorTreeAdapter.getGroupId(CursorTreeAdapter.java:192)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.widget.ExpandableListConnector.getItemId(ExpandableListConnector.java:421)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.widget.AdapterView.getItemIdAtPosition(AdapterView.java:745)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.widget.AdapterView.setSelectedPositionInt(AdapterView.java:1088)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.widget.AbsListView.onTouchEvent(AbsListView.java:2744)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.widget.ListView.onTouchEvent(ListView.java:3669)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.view.View.dispatchTouchEvent(View.java:3885)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:903)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
01-03 21:48:06.664: E/AndroidRuntime(16844): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1769)
01-03 21:48:06.664: E/AndroidRuntime(16844): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1135)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
01-03 21:48:06.664: E/AndroidRuntime(16844): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1753)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2227)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.view.ViewRoot.handleMessage(ViewRoot.java:1886)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.os.Handler.dispatchMessage(Handler.java:99)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.os.Looper.loop(Looper.java:130)
01-03 21:48:06.664: E/AndroidRuntime(16844): at android.app.ActivityThread.main(ActivityThread.java:3687)
01-03 21:48:06.664: E/AndroidRuntime(16844): at java.lang.reflect.Method.invokeNative(Native Method)
01-03 21:48:06.664: E/AndroidRuntime(16844): at java.lang.reflect.Method.invoke(Method.java:507)
01-03 21:48:06.664: E/AndroidRuntime(16844): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
01-03 21:48:06.664: E/AndroidRuntime(16844): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
01-03 21:48:06.664: E/AndroidRuntime(16844): at dalvik.system.NativeStart.main(Native Method)
我已经检查过其他类似的问题,但Stacktrace至少有一点指向实际的工作空间。但在这种情况下,我不知道我在做什么。我只能说,CursorTreeAdapter的getChildrenCursor在app崩溃时没有被调用,因为我在方法体中添加了println。
这就是我设置组游标的方式,我没有调用movetoFirst,因为它应该由CursorTreeAdapter管理并且看起来有效,因为它显示在具有适当内容的标题上。
public Cursor getGroupCursor(){
SQLiteDatabase db = helper.getReadableDatabase();
String sqlQuery = "SELECT DISTINCT STRFTIME('%m', " + INTAKE_KEY_DATE
+ ") as month, STRFTIME('%Y', " + INTAKE_KEY_DATE + ") as year " +
"FROM " + TABLENAME_INTAKE;
return db.rawQuery(sqlQuery, null);
}
如果您需要任何其他代码,请与我们联系
答案 0 :(得分:1)
找到它,
文档说明每个表都必须有一个名为_id的列,我的不是。至少现在:)