안드로이드 개발 질문/답변
(글 수 45,052)
이건 데이터베이스 어댑터만 몇번쨰 만드는건지 모르겠습니다.
어댑터 때문에 다른 진도가 계속 안나가네요.. OTL
어댑터를 만들 때마다 이상한 에러가 뜨더니,
이번에는 듣도보도못했던 에러가 떠서 저를 괴롭히고 있습니다.
[DDMS Log]
08-07 03:46:58.944: ERROR/AndroidRuntime(846): Uncaught handler: thread main exiting due to uncaught exception
08-07 03:46:58.962: ERROR/AndroidRuntime(846): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidhuman.project.HistoryView/com.androidhuman.project.HistoryView.HistoryView}: java.lang.IllegalArgumentException: column '_id' does not exist
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.os.Handler.dispatchMessage(Handler.java:99)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.os.Looper.loop(Looper.java:123)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.app.ActivityThread.main(ActivityThread.java:3948)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at java.lang.reflect.Method.invokeNative(Native Method)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at java.lang.reflect.Method.invoke(Method.java:521)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at dalvik.system.NativeStart.main(Native Method)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.widget.CursorAdapter.init(CursorAdapter.java:111)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.widget.CursorAdapter.<init>(CursorAdapter.java:90)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.widget.ResourceCursorAdapter.<init>(ResourceCursorAdapter.java:47)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.widget.SimpleCursorAdapter.<init>(SimpleCursorAdapter.java:85)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at com.androidhuman.project.HistoryView.HistoryView.refreshList(HistoryView.java:23)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at com.androidhuman.project.HistoryView.HistoryView.onCreate(HistoryView.java:35)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): ... 11 more
테이블 생성시 분명히 _id 컬럼을 만들었는데도 불구하고 계속 저렇게 뜹니다.
심지어는 _id 를 _ID나 _i로 변경해보아도 결과는 똑같이 나오네요.....
정말 별 것들이 다 태클을 거는군요 OTL.....
이런 문제는 어떻게 해결해야하나요?
다른 비슷한 데이터베이스 어댑터 만들어놓은게 있어서 그거랑 소스 비교해보고있는데, 뭐 때문에 그런지 도저히 모르겠습니다.
[테이블 생성 소스코드]
[refreshList]
[row.xml]
어댑터 때문에 다른 진도가 계속 안나가네요.. OTL
어댑터를 만들 때마다 이상한 에러가 뜨더니,
이번에는 듣도보도못했던 에러가 떠서 저를 괴롭히고 있습니다.
[DDMS Log]
08-07 03:46:58.944: ERROR/AndroidRuntime(846): Uncaught handler: thread main exiting due to uncaught exception
08-07 03:46:58.962: ERROR/AndroidRuntime(846): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidhuman.project.HistoryView/com.androidhuman.project.HistoryView.HistoryView}: java.lang.IllegalArgumentException: column '_id' does not exist
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.os.Handler.dispatchMessage(Handler.java:99)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.os.Looper.loop(Looper.java:123)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.app.ActivityThread.main(ActivityThread.java:3948)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at java.lang.reflect.Method.invokeNative(Native Method)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at java.lang.reflect.Method.invoke(Method.java:521)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at dalvik.system.NativeStart.main(Native Method)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.widget.CursorAdapter.init(CursorAdapter.java:111)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.widget.CursorAdapter.<init>(CursorAdapter.java:90)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.widget.ResourceCursorAdapter.<init>(ResourceCursorAdapter.java:47)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.widget.SimpleCursorAdapter.<init>(SimpleCursorAdapter.java:85)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at com.androidhuman.project.HistoryView.HistoryView.refreshList(HistoryView.java:23)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at com.androidhuman.project.HistoryView.HistoryView.onCreate(HistoryView.java:35)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
08-07 03:46:58.962: ERROR/AndroidRuntime(846): ... 11 more
테이블 생성시 분명히 _id 컬럼을 만들었는데도 불구하고 계속 저렇게 뜹니다.
심지어는 _id 를 _ID나 _i로 변경해보아도 결과는 똑같이 나오네요.....
정말 별 것들이 다 태클을 거는군요 OTL.....
이런 문제는 어떻게 해결해야하나요?
다른 비슷한 데이터베이스 어댑터 만들어놓은게 있어서 그거랑 소스 비교해보고있는데, 뭐 때문에 그런지 도저히 모르겠습니다.
[테이블 생성 소스코드]
// Table Basedata private static final String BASEDATA_TABLE = "basedata"; public static final String KEY_ROWID = "_id"; public static final String KEY_TAG = "tag"; public static final String KEY_MEMO = "memo"; public static final String KEY_YEAR = "year"; public static final String KEY_MONTH = "month"; public static final String KEY_DAY = "day"; private static final String BASEDATA_CREATE = "create table basedata (_id integer primary key autoincrement," + " tag text not null, memo text not null, year integer not null, " + "month integer not null, day integer not null);";
[refreshList]
private void refreshList(){ Cursor c = mDBAdapter.getAllContent(); startManagingCursor(c); String[] from = new String[]{DatabaseAdapter.KEY_TAG, DatabaseAdapter.KEY_MEMO, DatabaseAdapter.KEY_YEAR, DatabaseAdapter.KEY_MONTH, DatabaseAdapter.KEY_DAY}; int[] to = new int[]{R.id.row_tag, R.id.row_memo, R.id.row_year, R.id.row_month, R.id.row_date }; SimpleCursorAdapter listAdapter = new SimpleCursorAdapter(this, R.layout.row, c, from, to); setListAdapter(listAdapter); }
[row.xml]
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/row_tag"></TextView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/row_memo" android:textSize="20px"></TextView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/row_year"></TextView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/row_month"></TextView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/row_date"></TextView>
</LinearLayout>
1) 기존에 _id 가 없이 잘못 생성해놓았던 Table의 데이터베이스 파일이 지워지지 않고 남아있는 경우. -> 먼저 해당 application을 uninstall하고 나서 다시 올려서 사용하세요.
2) mDBAdapter.getAllContent(); 코드는 있지 않은데 저기서 수행하는 쿼리에서 _id 컬럼을 포함하지 않은 경우가 있을 수 있습니다.