Sebastian Klaiber
- Forum-Beiträge: 44
19.12.2010, 11:38:58 via Website
19.12.2010 11:38:58 via Website
Hi,
ich arbeite gerade an einer APP, bei der ich einen ExpandableListAdapter verwende die Daten für die Liste kommen aus einer Datenbank mit 2 Tabllen, Item, Category. Nun bekomm ich aber bei Logcat diese Fehlermeldung das die Spalte „_id“ nicht existiert, in meiner Tabelle Catagory definiere ich aber diese Spalte. Hab leider gerade keine Idee an was das liegen kann. Danke für eure Hilfe!
getGroupId vom ExpandableListAdapter
Hoffe der Code reicht ansonsten stell ich den Rest auch noch gerne zur Verfügung
chao
ich arbeite gerade an einer APP, bei der ich einen ExpandableListAdapter verwende die Daten für die Liste kommen aus einer Datenbank mit 2 Tabllen, Item, Category. Nun bekomm ich aber bei Logcat diese Fehlermeldung das die Spalte „_id“ nicht existiert, in meiner Tabelle Catagory definiere ich aber diese Spalte. Hab leider gerade keine Idee an was das liegen kann. Danke für eure Hilfe!
112-19 11:34:30.890: ERROR/AndroidRuntime(224): Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
212-19 11:34:30.890: ERROR/AndroidRuntime(224): at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314)
312-19 11:34:30.890: ERROR/AndroidRuntime(224): at de.android.shoppinglist.CategoriesAdapter.getGroupId(CategoriesAdapter.java:60)
412-19 11:34:30.890: ERROR/AndroidRuntime(224): at android.widget.ExpandableListConnector.getItemId(ExpandableListConnector.java:422)
512-19 11:34:30.890: ERROR/AndroidRuntime(224): at android.widget.AdapterView.getItemIdAtPosition(AdapterView.java:745)
612-19 11:34:30.890: ERROR/AndroidRuntime(224): at android.widget.AdapterView.setSelectedPositionInt(AdapterView.java:1081)
712-19 11:34:30.890: ERROR/AndroidRuntime(224): at android.widget.ListView.setAdapter(ListView.java:445)
812-19 11:34:30.890: ERROR/AndroidRuntime(224): at android.widget.ExpandableListView.setAdapter(ExpandableListView.java:475)
912-19 11:34:30.890: ERROR/AndroidRuntime(224): at android.app.ExpandableListActivity.setListAdapter(ExpandableListActivity.java:246)
1012-19 11:34:30.890: ERROR/AndroidRuntime(224): at de.android.shoppinglist.ShoppingList.loadCategories(ShoppingList.java:208)
1112-19 11:34:30.890: ERROR/AndroidRuntime(224): at de.android.shoppinglist.ShoppingList.onCreate(ShoppingList.java:60)
1212-19 11:34:30.890: ERROR/AndroidRuntime(224): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
1312-19 11:34:30.890: ERROR/AndroidRuntime(224): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
1412-19 11:34:30.890: ERROR/AndroidRuntime(224): ... 11 more
212-19 11:34:30.890: ERROR/AndroidRuntime(224): at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314)
312-19 11:34:30.890: ERROR/AndroidRuntime(224): at de.android.shoppinglist.CategoriesAdapter.getGroupId(CategoriesAdapter.java:60)
412-19 11:34:30.890: ERROR/AndroidRuntime(224): at android.widget.ExpandableListConnector.getItemId(ExpandableListConnector.java:422)
512-19 11:34:30.890: ERROR/AndroidRuntime(224): at android.widget.AdapterView.getItemIdAtPosition(AdapterView.java:745)
612-19 11:34:30.890: ERROR/AndroidRuntime(224): at android.widget.AdapterView.setSelectedPositionInt(AdapterView.java:1081)
712-19 11:34:30.890: ERROR/AndroidRuntime(224): at android.widget.ListView.setAdapter(ListView.java:445)
812-19 11:34:30.890: ERROR/AndroidRuntime(224): at android.widget.ExpandableListView.setAdapter(ExpandableListView.java:475)
912-19 11:34:30.890: ERROR/AndroidRuntime(224): at android.app.ExpandableListActivity.setListAdapter(ExpandableListActivity.java:246)
1012-19 11:34:30.890: ERROR/AndroidRuntime(224): at de.android.shoppinglist.ShoppingList.loadCategories(ShoppingList.java:208)
1112-19 11:34:30.890: ERROR/AndroidRuntime(224): at de.android.shoppinglist.ShoppingList.onCreate(ShoppingList.java:60)
1212-19 11:34:30.890: ERROR/AndroidRuntime(224): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
1312-19 11:34:30.890: ERROR/AndroidRuntime(224): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
1412-19 11:34:30.890: ERROR/AndroidRuntime(224): ... 11 more
getGroupId vom ExpandableListAdapter
1public long getGroupId(int groupPosition) {
2 Cursor categoriesCursor = (Cursor) getGroup(groupPosition);
3 if (categoriesCursor != null && !categoriesCursor.isNull(groupPosition)) {
4 return categoriesCursor.getInt(categoriesCursor.getColumnIndexOrThrow(Category.ID));
5
6 }
7 return -1;
8 }
2 Cursor categoriesCursor = (Cursor) getGroup(groupPosition);
3 if (categoriesCursor != null && !categoriesCursor.isNull(groupPosition)) {
4 return categoriesCursor.getInt(categoriesCursor.getColumnIndexOrThrow(Category.ID));
5
6 }
7 return -1;
8 }
1public class Category {
2
3 public static final String TABLE_NAME = "catagories";
4 public static final String ID = "_id";
5 public static final String NAME = "name";
6 public static final String CREATED_AT = "created_at";
7 public static final String SQL_CREATE = "CREATE TABLE " + TABLE_NAME + " ("
8 + ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + NAME + " TEXT,"
9 + CREATED_AT + " TIMESTAMP" + ");";
10}
2
3 public static final String TABLE_NAME = "catagories";
4 public static final String ID = "_id";
5 public static final String NAME = "name";
6 public static final String CREATED_AT = "created_at";
7 public static final String SQL_CREATE = "CREATE TABLE " + TABLE_NAME + " ("
8 + ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + NAME + " TEXT,"
9 + CREATED_AT + " TIMESTAMP" + ");";
10}
Hoffe der Code reicht ansonsten stell ich den Rest auch noch gerne zur Verfügung
chao
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.