1

以下は、Simple Cursor Tree Adapter のサブクラスである内部クラスと一緒に私の活動からのコードです。問題は、エラーが発生したの子要素をクリックしたときです

protected void onStart() {
    super.onStart();
    SQLiteDatabase db = new ToDoDatabase(getApplicationContext())
            .getWritableDatabase();
    Cursor cursor = db.query(true, ToDoDatabase.TABLE_NAME, null, null,
            null, null, null, null, null);
    CustomCursorTreeAdapter cursorTreeAdapter = new CustomCursorTreeAdapter(
            getApplicationContext(), cursor, R.layout.group_item_layout,
            new String[] { ToDoDatabase.TASK_NAME_FORMAT_DATE },
            new int[] { R.id.groupItem }, R.layout.child_item_layout,
            new String[] { ToDoDatabase.TASK_TIME },
            new int[] { R.id.childItem });
    drawerList.setAdapter(cursorTreeAdapter);
}

public class CustomCursorTreeAdapter extends SimpleCursorTreeAdapter {

    public CustomCursorTreeAdapter(Context context, Cursor cursor,
            int groupLayout, String[] groupFrom, int[] groupTo,
            int childLayout, String[] childFrom, int[] childTo) {
        super(context, cursor, groupLayout, groupFrom, groupTo,
                childLayout, childFrom, childTo);
    }

    @Override
    protected Cursor getChildrenCursor(Cursor group) {
        SQLiteDatabase db = new ToDoDatabase(getApplicationContext())
                .getWritableDatabase();
        return db
                .query(
                        ToDoDatabase.TABLE_NAME,
                        new String[] { ToDoDatabase.TASK_TIME },
                        ToDoDatabase.TASK_NAME_FORMAT_DATE + " = ? ",
                        new String[] { group.getString(group
                                .getColumnIndex(ToDoDatabase.TASK_NAME_FORMAT_DATE)) },
                        null, null, null, null);
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
}

私のlogcatからの出力は以下の通りです。さらに、expendableList groupitem に対して同じ値を取得しています。たとえば、「A」が 2 つある場合、同じ子アイテムで「A」が 2 つ取得されます。また、私は Android の初心者です。

     10-14 23:52:11.908: E/AndroidRuntime(28080): java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.database.CursorWindow.nativeGetLong(Native Method)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.database.CursorWindow.getLong(CursorWindow.java:515)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:75)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.widget.CursorTreeAdapter$MyCursorHelper.getId(CursorTreeAdapter.java:436)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.widget.CursorTreeAdapter.getChildId(CursorTreeAdapter.java:173)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.widget.ExpandableListConnector.getItemId(ExpandableListConnector.java:427)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.widget.AdapterView.getItemIdAtPosition(AdapterView.java:756)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.widget.AdapterView.setSelectedPositionInt(AdapterView.java:1128)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.widget.AbsListView.onTouchEvent(AbsListView.java:3165)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.view.View.dispatchTouchEvent(View.java:5604)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2054)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1815)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2060)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1829)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2060)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1829)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2060)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1829)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2060)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1829)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1917)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1376)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.app.Activity.dispatchTouchEvent(Activity.java:2364)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.dispatchTouchEvent(ActionBarActivityDelegateICS.java:255)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1865)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.view.View.dispatchPointerEvent(View.java:5784)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2890)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2466)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:845)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2475)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.os.Handler.dispatchMessage(Handler.java:99)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.os.Looper.loop(Looper.java:137)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at android.app.ActivityThread.main(ActivityThread.java:4448)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at java.lang.reflect.Method.invokeNative(Native Method)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at java.lang.reflect.Method.invoke(Method.java:511)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at          com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
     10-14 23:52:11.908: E/AndroidRuntime(28080):   at dalvik.system.NativeStart.main(Native Method)
4

1 に答える 1