运行我的应用时出现此错误:
01-09 17:44:29.317:E / AndroidRuntime(3697):引起:android.database.sqlite.SQLiteException:没有这样的列:title :,编译时:SELECT title,_id FROM Kwl
我已经查找了其他解决方案,但它们都归因于我所缺少的“_id”列。
以下是我的活动中的相关摘录:
final DatabaseHelper db = new DatabaseHelper(this);
Cursor c = db.getKwlNames();
startManagingCursor(c);
String[] from = new String[] { DatabaseHelper.KWL_TITLE, DatabaseHelper.KWL_ID };
int[] to = new int[] { R.id.titleLI_title, R.id.titleLI_id };
SimpleCursorAdapter sca = new SimpleCursorAdapter(this,
R.layout.title_list_item, c, from, to);
listView.setAdapter(sca);
和我的DatabaseHelper中的代码:
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "KWL_DB";
public static final String KWL_TABLE = "Kwl";
public static final String CHART_TABLE = "Chart";
public static final int DATABASE_VERSION = 1;
public static final String KWL_TITLE = "title";
public static final String KWL_ORDER = "seq";
public static final String KWL_HASE = "hase";
public static final String KWL_ID = "_id";
public static final String CHART_TYPE = "type";
public static final String CHART_ORDER = "seq";
public static final String CHART_VALUE = "val";
public static final String CHART_KWL_TITLE = "title";
static final String CREATE_KWL = "CREATE TABLE " + KWL_TABLE + " (" + KWL_ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + KWL_TITLE
+ " TEXT, " + KWL_ORDER + " INTEGER, " + KWL_HASE
+ " INTEGER)";
static final String CREATE_CHART = "CREATE TABLE " + CHART_TABLE + " (" + CHART_KWL_TITLE
+ " TEXT, " + CHART_VALUE + " TEXT, " + CHART_ORDER
+ " INTEGER, " + CHART_TYPE + " TEXT)";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_KWL);
db.execSQL(CREATE_CHART);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public Cursor getKwlNames() {
SQLiteDatabase db = this.getReadableDatabase();
return db.rawQuery("SELECT " + KWL_TITLE + " , " + KWL_ID + " FROM " + KWL_TABLE, null);
}
}