在一
猜测
您的问题是因为您没有名为
圣婴
,在这种情况下,日志将包含以下内容:
06-07 10:53:53.957 1178-1178/so50635292.so50635292 E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{so50635292.so50635292/so50635292.so50635292.MainActivity}: java.lang.IllegalArgumentException: column '_id' does not exist
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:302)
at android.widget.CursorAdapter.init(CursorAdapter.java:168)
at android.widget.CursorAdapter.<init>(CursorAdapter.java:145)
at android.widget.ResourceCursorAdapter.<init>(ResourceCursorAdapter.java:91)
at android.widget.SimpleCursorAdapter.<init>(SimpleCursorAdapter.java:104)
at so50635292.so50635292.MainActivity.populate(MainActivity.java:31)
at so50635292.so50635292.MainActivity.onCreate(MainActivity.java:23)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)Â
at android.app.ActivityThread.access$600(ActivityThread.java:130)Â
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)Â
at android.os.Handler.dispatchMessage(Handler.java:99)Â
at android.os.Looper.loop(Looper.java:137)Â
at android.app.ActivityThread.main(ActivityThread.java:4745)Â
at java.lang.reflect.Method.invokeNative(Native Method)Â
at java.lang.reflect.Method.invoke(Method.java:511)Â
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)Â
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)Â
at dalvik.system.NativeStart.main(Native Method)Â
相关部分是
java.lang.IllegalArgumentException: column '_id' does not exist
游标适配器需要此列,它还应该是rowid的别名。行的别名是定义为
?? INTEGER PRIMARY KEY
,也可以对可选的、后续的、自动递增关键字进行编码。然而,一般情况下,它不应该因为有间接费用编码自动增量。
要解决此问题,可以在
onCreate
方法,然后删除应用程序的数据或卸载该应用程序,然后重新运行该应用程序。
您也可以在查询数据时通过更改
String query = "SELECT * FROM " + TABLE_NAME;
到
String query = "SELECT rowid AS _id,* FROM " + TABLE_NAME;