我试图从android中的数据库中检索整个数据...
<小时/> Sqlite查询: -
Cursor c = db.rawQuery("SELECT * FROM stud",null);
但例外: -
07-04 18:47:26.249: E/CursorWindow(8314): Bad request for field slot 0,-1. numRows = 1, numColumns = 8
07-04 18:47:26.259: D/AndroidRuntime(8314): Shutting down VM
07-04 18:47:26.259: W/dalvikvm(8314): threadid=1: thread exiting with uncaught exception (group=0x40015560)
07-04 18:47:26.329: E/AndroidRuntime(8314): FATAL EXCEPTION: main
07-04 18:47:26.329: E/AndroidRuntime(8314): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.StudentInfoManagement/com.my.StudentInfoManagement.ListData}: java.lang.IllegalStateException: get field slot from row 0 col -1 failed
07-04 18:47:26.329: E/AndroidRuntime(8314): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
07-04 18:47:26.329: E/AndroidRuntime(8314): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-04 18:47:26.329: E/AndroidRuntime(8314): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-04 18:47:26.329: E/AndroidRuntime(8314): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-04 18:47:26.329: E/AndroidRuntime(8314): at android.os.Handler.dispatchMessage(Handler.java:99)
07-04 18:47:26.329: E/AndroidRuntime(8314): at android.os.Looper.loop(Looper.java:123)
07-04 18:47:26.329: E/AndroidRuntime(8314): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-04 18:47:26.329: E/AndroidRuntime(8314): at java.lang.reflect.Method.invokeNative(Native Method)
07-04 18:47:26.329: E/AndroidRuntime(8314): at java.lang.reflect.Method.invoke(Method.java:507)
07-04 18:47:26.329: E/AndroidRuntime(8314): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-04 18:47:26.329: E/AndroidRuntime(8314): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-04 18:47:26.329: E/AndroidRuntime(8314): at dalvik.system.NativeStart.main(Native Method)
07-04 18:47:26.329: E/AndroidRuntime(8314): Caused by: java.lang.IllegalStateException: get field slot from row 0 col -1 failed
07-04 18:47:26.329: E/AndroidRuntime(8314): at android.database.CursorWindow.getString_native(Native Method)
07-04 18:47:26.329: E/AndroidRuntime(8314): at android.database.CursorWindow.getString(CursorWindow.java:329)
07-04 18:47:26.329: E/AndroidRuntime(8314): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:49)
07-04 18:47:26.329: E/AndroidRuntime(8314): at com.my.StudentInfoManagement.DataHelper.selectAll(DataHelper.java:52)
07-04 18:47:26.329: E/AndroidRuntime(8314): at com.my.StudentInfoManagement.ListData.onCreate(ListData.java:18)
07-04 18:47:26.329: E/AndroidRuntime(8314): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-04 18:47:26.329: E/AndroidRuntime(8314): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
07-04 18:47:26.329: E/AndroidRuntime(8314): ... 11 more
答案 0 :(得分:0)
id
(primary_Key)名称转换为:_id
&amp;它成功运行,
现在,如果你说为什么在实施phone_contact:here之后将鼠标悬停在 Contacts._ID 之上,你会发现与之关联的_id
字符串。
private static final String[] CONTACTS_PROJECTION = new String[]
{
Contacts._ID,
Contacts.DISPLAY_
};