我有一个SQLite数据库,它存储所有坐标+描述,以便在录制标记时显示它们。我正在使用此代码来检索所有描述:
protected boolean onTap(int index) {
db = openHelper.getWritableDatabase();
String[] result_columns = new String[] {COL_DESCRI};
Cursor cur = db.query(true, TABLE_COORD, result_columns,
null, null, null, null, null, null);
cur.moveToFirst();
while (cur.isAfterLast() == false) {
String description = cur.getString(cur.getColumnIndexOrThrow("Description"));
AlertDialog.Builder dialog = new AlertDialog.Builder(Geo.this);
dialog.setTitle("Infos.");
dialog.setMessage(description);
dialog.setPositiveButton("OK", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
dialog.show();
cur.moveToNext();
}
cur.close();
db.close();
return true;
然而,我有一个奇怪的问题,表明我没有说明栏,我很确定我有它。
08-23 02:45:02.848: ERROR/AndroidRuntime(287): Uncaught handler: thread main exiting due to uncaught exception
08-23 02:45:02.890: ERROR/AndroidRuntime(287): android.database.sqlite.SQLiteException: no such column: Description: , while compiling: SELECT DISTINCT Description FROM table_coordonnées
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at android.database.sqlite.SQLiteProgram.native_compile(Native Method)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at android.database.sqlite.SQLiteProgram.compile(SQLiteProgram.java:110)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:49)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1220)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1107)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1065)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at carburant.android.com.Geo$ItemizedOverlayPerso.onTap(Geo.java:239)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at com.google.android.maps.ItemizedOverlay.onTap(ItemizedOverlay.java:453)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at com.google.android.maps.OverlayBundle.onTap(OverlayBundle.java:83)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at com.google.android.maps.MapView$1.onSingleTapUp(MapView.java:346)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at android.view.GestureDetector.onTouchEvent(GestureDetector.java:506)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at com.google.android.maps.MapView.onTouchEvent(MapView.java:628)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at android.view.View.dispatchTouchEvent(View.java:3709)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:852)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at android.os.Handler.dispatchMessage(Handler.java:99)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at android.os.Looper.loop(Looper.java:123)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at android.app.ActivityThread.main(ActivityThread.java:4363)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at java.lang.reflect.Method.invokeNative(Native Method)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at java.lang.reflect.Method.invoke(Method.java:521)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-23 02:45:02.890: ERROR/AndroidRuntime(287): at dalvik.system.NativeStart.main(Native Method)
请问有什么问题? 谢谢你的帮助。
答案 0 :(得分:1)
它看起来像“没有这样的列:描述”,所以你必须检查一次数据库,并且你的方向也是错误的。
您正在onTap()
方法中获取坐标,在获取光标后,您将获取循环并在循环中编写显示对话框的代码。
所以your code will give you description of only last record.
你必须为所有坐标创建描述数组,然后在onTap(int index)
中你需要得到坐标using index variable of onTap(int index) method
答案 1 :(得分:1)
请检查您的创建语句和查询。我会到处使用小写。在编辑中,您可以编写coordoonnees和table_coordoonnees。两者都不匹配。
SQLites错误消息总是非常有用。如果SQLite告诉您有关缺少的表或列,则此项目将被定义为缺失或拼写错误。