我已經實現了一個CursorTreeAdapter,並使用它從包含有關days的信息的sqlite數據庫中獲取數據。現在我想把這些日子分組爲幾個月。爲此,我實現了一個返回Months + Years列表的Cursor,以及一個檢索應該在該組中的日子的子游標。CursorTreeAdapter和Expandable ListView
我的組光標似乎運行得很好,我將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在應用程序崩潰時沒有被調用,因爲我在方法體中添加了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);
}
如果您需要任何額外的代碼,讓我知道