When I try to create the a table the very first time, I always get this error message:
sqlite returned: error code = 1, msg = AUTOINCREMENT is only allowed
on an INTEGER PRIMARY KEY
My code looks like this:
// debuggin identifier
private static final String TAG = DatabaseOpenHandler.class.getSimpleName();
// name and verison of the database
private static final String DATABASE_NAME = "OpenConfApp";
private static final int DATABASE_VERSION = 1;
// name and attributes of the table notes
public static final String TABLE_NAME_NOTES = "notes";
public static final String _NOTE_ID = "_noteId";
public static final String NOTE_CONFERENCE = "conferenceId";
public static final String NOTE_DATE = "dateInMillis";
public static final String NOTE_TEXT = "noteText";
// create table notes
public static final String TABLE_NOTES_CREATE = "CREATE TABLE "
+ TABLE_NAME_NOTES + " (" + _NOTE_ID
+ "INTEGER PRIMARY KEY AUTOINCREMENT, " + NOTE_CONFERENCE
+ " INTEGER, " + NOTE_DATE + " INTEGER, " + NOTE_TEXT
+ " INTEGER);";
// drop table notes
public static final String TABLE_NOTES_DROP = "DROP TABLE IF EXIST "
+ TABLE_NAME_NOTES;
public DatabaseOpenHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
Log.d(TAG, "onCreate called");
db.execSQL(TABLE_NOTES_CREATE);
}
Sorry, I’m new to Android programming.
Your code is correct Just you missed a space before your first integer statement.Write this: