データベースからデータを取得する際に問題があります。LogCat で、そのような列の timeinstance がないと不平を言いました。これは、データベースに追加した新しい列です。フェッチのみに問題がありますが、 createNewList にはその列に問題はありません。何が問題なのですか?データベースクラス全体を投稿しました。
public class TrackerDBAdapter {
public static final String KEY_ROWID = "_id";
public static final String KEY_IDNUM = "_idnum";
public static final String KEY_SIMCARD = "_simcard";
public static final String KEY_DESCRIPTION = "_description";
public static final String KEY_MODEL = "_model";
public static final String KEY_TIMEINSTANCE = "timeinstance";
private static final String TAG = "TrackerDBAdapter";
private static final String DATABASE_NAME = "DBTrackerList";
private static final String SQLITE_TABLE = "TBTrackerList";
private static final int DATABASE_VERSION = 1;
private final Context mCtx;
private static final String DATABASE_CREATE =
"CREATE TABLE if not exists " + SQLITE_TABLE + " (" +
KEY_ROWID + " integer PRIMARY KEY autoincrement," +
KEY_IDNUM + "," +
KEY_SIMCARD + "," +
KEY_DESCRIPTION + "," +
KEY_MODEL + "," +
KEY_TIMEINSTANCE + "," +
" UNIQUE (" + KEY_IDNUM +"));";
private DatabaseHelper mDbHelper;
private SQLiteDatabase mDb;
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
Log.w(TAG, DATABASE_CREATE);
db.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + SQLITE_TABLE);
onCreate(db);
}
}
public TrackerDBAdapter(Context ctx) {
this.mCtx = ctx;
}
public TrackerDBAdapter open() throws SQLException {
mDbHelper = new DatabaseHelper(mCtx);
mDb = mDbHelper.getWritableDatabase();
return this;
}
public void close() {
if (mDbHelper != null) {
mDbHelper.close();
}
}
public long createNewList(String idnum, String simnum,
String description, String model, String time) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_IDNUM, idnum);
initialValues.put(KEY_SIMCARD, simnum);
initialValues.put(KEY_DESCRIPTION, description);
initialValues.put(KEY_MODEL, model);
initialValues.put(KEY_TIMEINSTANCE, time);
return mDb.insert(SQLITE_TABLE, null, initialValues);
}
public boolean deleteAllTrackerInTheList() {
int doneDelete = 0;
doneDelete = mDb.delete(SQLITE_TABLE, null , null);
Log.w(TAG, Integer.toString(doneDelete));
return doneDelete > 0;
}
@SuppressLint("NewApi")
public Cursor fetchListBySimcardNum(String inputText) throws SQLException {
Log.w(TAG, inputText);
Cursor mCursor = null;
if (inputText == null || inputText.length () == 0) {
mCursor = mDb.query(SQLITE_TABLE, new String[] {KEY_ROWID,
KEY_IDNUM, KEY_SIMCARD, KEY_DESCRIPTION, KEY_MODEL, KEY_TIMEINSTANCE},
null, null, null, null, null);
}
else {
mCursor = mDb.query(true, SQLITE_TABLE, new String[] {KEY_ROWID,
KEY_IDNUM, KEY_SIMCARD, KEY_DESCRIPTION, KEY_MODEL, KEY_TIMEINSTANCE},
KEY_SIMCARD + " like '%" + inputText + "%'", null,
null, null, null, null);
}
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
@SuppressLint("NewApi")
public Cursor fetchListByIDNum(String inputText) throws SQLException {
Log.w(TAG, inputText);
Cursor mCursor = null;
if (inputText == null || inputText.length () == 0) {
mCursor = mDb.query(SQLITE_TABLE, new String[] {KEY_ROWID,
KEY_IDNUM, KEY_SIMCARD, KEY_DESCRIPTION, KEY_MODEL, KEY_TIMEINSTANCE},
null, null, null, null, null);
}
else {
mCursor = mDb.query(true, SQLITE_TABLE, new String[] {KEY_ROWID,
KEY_IDNUM, KEY_SIMCARD, KEY_DESCRIPTION, KEY_MODEL, KEY_TIMEINSTANCE},
KEY_IDNUM + " like '%" + inputText + "%'", null,
null, null, null, null);
}
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
public Cursor fetchAllTrackerInTheList() {
Cursor mCursor = mDb.query(SQLITE_TABLE, new String[] {KEY_ROWID,
KEY_IDNUM, KEY_SIMCARD, KEY_DESCRIPTION, KEY_MODEL, KEY_TIMEINSTANCE},
null, null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
public int getLastInsertedID() {
int id = 0;
Cursor mCursor = mDb.query(SQLITE_TABLE, new String[] {KEY_ROWID,
KEY_IDNUM, KEY_SIMCARD, KEY_DESCRIPTION, KEY_MODEL, KEY_TIMEINSTANCE},
null, null, null, null, null);
if (mCursor.moveToLast()) {
id = mCursor.getInt(0);
}
return id;
}
public void insertSomeCountries() {
createNewList("AFG","Afghanistan","Asia","Southern", "Central Asia");
}
}