lundi 26 janvier 2015

CREATE TABLE statement error - table does not exist

Here is my code:



public class DBAdapter {
static final String KEY_ID = "_id";
static final String KEY_TITLE = "title";
static final String KEY_DESCRIPTION = "description";
static final String KEY_TYPE = "type";
static final String KEY_LONG = "lon";
static final String KEY_LAT = "lat";
static final String KEY_NOTE_ID = "note_id";
static final String KEY_PATH = "path";
static final String TAG = "DBAdapter";
static final String DATABASE_NAME = "NotesDB5";
static final String DATABASE_TABLE = "textnotes";
static final String DATABASE_TABLE2 = "soundimage";
static final int DATABASE_VERSION = 1;
static final String TABLE1_CREATE =
"CREATE TABLE IF NOT EXISTS textnotes (_id integer primary key autoincrement not null, title text not null,"
+ " description text, type text not null, lon double not null, lat double not null)";
static final String TABLE2_CREATE =
"CREATE TABLE IF NOT EXISTS soundimage (_id integer primary key autoincrement not null, "
+ "note_id integer not null, path text not null)";
Context context;
SQLiteDatabase db;
DatabaseHelper DBHelper;

private static class DatabaseHelper extends SQLiteOpenHelper
{
DatabaseHelper(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(TABLE1_CREATE);
db.execSQL(TABLE2_CREATE);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS" + DATABASE_TABLE);
db.execSQL("DROP TABLE IF EXISTS" + DATABASE_TABLE2);
onCreate(db);
}

In the DBAdapter class i have a method to insert values:

public long insertImageSound(long id, String path) {
ContentValues value = new ContentValues();
value.put(KEY_NOTE_ID, id);
value.put(KEY_PATH, path);

return db.insert(DATABASE_TABLE2, null, value);
}


When i execute the code and try to save an entry to the DATABASE_TABLE2 Ι take this error:



01-26 11:14:11.474: E/SQLiteLog(1901): (1) no such table: soundimage
01-26 11:14:11.491: E/SQLiteDatabase(1901): Error inserting path=/storage/emulated/0/audio_20150126_111405.3gp note_id=24
01-26 11:14:11.491: E/SQLiteDatabase(1901): android.database.sqlite.SQLiteException: no such table: soundimage (code 1): , while compiling: INSERT INTO soundimage(path,note_id) VALUES (?,?)


note_id and path have values (not null)


Whats the problem?


Aucun commentaire:

Enregistrer un commentaire