これは私の ExpandableList アクティビティのコードです
public class ExpenseEditorActivity extends ExpandableListActivity {
MyDOA projedit = new MyDOA(ExpenseEditorActivity.this, Environment.getExternalStorageDirectory());
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
lv_Expenses = getExpandableListView();
projedit.open();
fillExpenseList();
lv_Expenses.setAdapter(exp_adapter);
}
public void fillExpenseList(){
Cursor groupCursor=projedit.fetchGroup(SelectProjectActivity.sel_id);
startManagingCursor(groupCursor);
groupCursor.moveToFirst();
exp_adapter=new MyExpandableListAdapter(groupCursor,this, R.layout.expense_list_expandableitem, R.layout.expense_list_item,new String[]{"expdate"}, new int[]{R.id.label_date},new String[]{"expname","expamount"},new int[]{R.id.label_eh,R.id.label_amount});
}
public class MyExpandableListAdapter extends SimpleCursorTreeAdapter {
public MyExpandableListAdapter(Cursor cursor, Context context,int groupLayout,
int childLayout, String[] groupFrom, int[] groupTo, String[] childrenFrom, int[] childrenTo) {
super(context, cursor, groupLayout, groupFrom, groupTo,childLayout, childrenFrom, childrenTo);
}
@Override
protected Cursor getChildrenCursor(Cursor groupCursor) {
Cursor childCursor= projedit.fetchChildren(SelectProjectActivity.sel_id, groupCursor.getString(0));
startManagingCursor(childCursor);
childCursor.moveToFirst();
return childCursor;
}
}
}
expandablelistview が展開されていない (デフォルト) 限り、アクティビティは正常に実行されていますが、「グループ」をクリックして展開すると、次の logcat エラーが発生します。
FATAL EXCEPTION: main java.lang.IllegalStateException: get field slot from row 1 col -1 failed
at android.database.CursorWindow.getLong_native(Native Method)
at android.database.CursorWindow.getLong(CursorWindow.java:412)
at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:108)
at android.widget.CursorTreeAdapter$MyCursorHelper.getId(CursorTreeAdapter.java:437)
at android.widget.CursorTreeAdapter.getGroupId(CursorTreeAdapter.java:192)
at android.widget.ExpandableListConnector.getItemId(ExpandableListConnector.java:421)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:1992)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
誰かがこれを読んで、「グループ.
また、コードですべてのグループを展開済みとして設定した場合。アクティビティが開始されるとすぐに同じエラーが発生します(明らかに)
編集
public Cursor fetchChildren(int i,String date){
Cursor cursor=database.query("expense,expensehead", new String[]{"expense._id","expensehead.expname","expense.expamount","expensehead._id"},
"expense.project_id=\""+i+"\" and expensehead.project_id=\""+i+"\" and expense.exphead_id=expensehead._id and expense.expdate=\""+date+"\"", null, null, null, null);
return cursor;
}
public Cursor fetchGroup(int i){
Cursor cursor=database.query("expense", new String[]{"expdate"}, "project_id=\""+i+"\"",null, "expense.expdate", null, null);
return cursor;
}
私のデータベースは次のようになります
database.execSQL("create table project(_id integer primary key autoincrement, "+
"name text not null, " +
"amount real not null, " +
"startdate text not null, " +
"enddate text not null, "+
"avgbase integer not null);");
database.execSQL("create table expensehead(_id integer primary key autoincrement, "+
"expname text not null, "+
"project_id integer not null);");
database.execSQL("create table expense(_id integer primary key autoincrement, "+
"expamount real not null, "+
"expdate text not null, "+
"exphead_id integer not null, "+
"project_id integer not null);");