私は自分の問題を解決するためにWebで検索しましたが、見つけた解決策のどれも私にはうまくいかないので、それが私の問題です。
私はdaoを持っています:
public class AqntCategoryDAO extends SQLiteOpenHelper{
public static abstract class AqntCategoryEntry implements BaseColumns {
public static final String TABLE_NAME = "category";
public static final String COLUMN_NAME_NAME = "name";
public static final String COLUMN_NAME_TAG = "tag";
public static final String COLUMN_NAME_STATUS = "status";
}
//globals
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "AquiNaoTemPlaces.db";
public static String[] columns = {
AqntCategoryEntry._ID,
AqntCategoryEntry.COLUMN_NAME_NAME,
AqntCategoryEntry.COLUMN_NAME_TAG,
AqntCategoryEntry.COLUMN_NAME_STATUS
};
public AqntCategoryDAO(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
StringBuffer sql_create = new StringBuffer();
sql_create.append("CREATE TABLE IF NOT EXISTS "+AqntCategoryEntry.TABLE_NAME);
sql_create.append("( ");
sql_create.append(AqntCategoryEntry._ID+" INTEGER PRIMARY KEY AUTOINCREMENT,");
sql_create.append(AqntCategoryEntry.COLUMN_NAME_NAME+" TEXT,");
sql_create.append(AqntCategoryEntry.COLUMN_NAME_TAG+" TEXT,");
sql_create.append(AqntCategoryEntry.COLUMN_NAME_STATUS+" INTEGER");
sql_create.append(" )");
Log.i("SQL: ",sql_create.toString());
db.execSQL(sql_create.toString());
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + AqntCategoryEntry.TABLE_NAME);
onCreate(db);
}
...
と:
public class AqntPlacesDAO extends SQLiteOpenHelper{
public static abstract class AqntPlacesEntry implements BaseColumns {
public static final String TABLE_NAME = "places";
public static final String COLUMN_NAME_NAME = "name";
public static final String COLUMN_NAME_LATITUDEE6 = "latitudeE6";
public static final String COLUMN_NAME_LONGITUDEE6 = "longitudeE6";
public static final String COLUMN_NAME_RATE = "rate";
public static final String COLUMN_NAME_STATUS = "status";
}
//globals
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "AquiNaoTemPlaces.db";
public static String[] columns = {
AqntPlacesEntry._ID,
AqntPlacesEntry.COLUMN_NAME_NAME,
AqntPlacesEntry.COLUMN_NAME_LATITUDEE6,
AqntPlacesEntry.COLUMN_NAME_LONGITUDEE6,
AqntPlacesEntry.COLUMN_NAME_RATE,
AqntPlacesEntry.COLUMN_NAME_STATUS
};
public AqntPlacesDAO(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
StringBuffer sql_create = new StringBuffer();
sql_create.append("CREATE TABLE IF NOT EXISTS "+AqntPlacesEntry.TABLE_NAME);
sql_create.append("( ");
sql_create.append(AqntPlacesEntry._ID+" INTEGER PRIMARY KEY AUTOINCREMENT,");
sql_create.append(AqntPlacesEntry.COLUMN_NAME_NAME+" TEXT,");
sql_create.append(AqntPlacesEntry.COLUMN_NAME_LATITUDEE6+" TEXT,");
sql_create.append(AqntPlacesEntry.COLUMN_NAME_LONGITUDEE6+" TEXT,");
sql_create.append(AqntPlacesEntry.COLUMN_NAME_RATE+" REAL,");
sql_create.append(AqntPlacesEntry.COLUMN_NAME_STATUS+" INTEGER");
sql_create.append(" )");
Log.i("SQL: ",sql_create.toString());
db.execSQL(sql_create.toString());
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF `EXISTS` " + AqntPlacesEntry.TABLE_NAME);
onCreate(db);
}
...
そして私がしようとすると
AqntPlacesDAO daoPlace = new AqntPlacesDAO(context);
AqntCategoryDAO catAuxDAO = new AqntCategoryDAO(context);
List<AqntPlaces> places = daoPlace.getPlaces();
List<AqntCategory> catss = catAuxDAO.getCategories();
daoPlace.close();
catAuxDAO.close();
それは最初の1つだけを作成し、もう1つはエラーを表示します。
02-19 22:51:29.083: E/AndroidRuntime(9336): android.database.sqlite.SQLiteException: no such table: category: , while compiling: SELECT _id, name, tag, status FROM category
しかし、DAOを1つだけ実行すると、機能します。
誰かが私が間違っていることを知っていますか?