This is a very basic question. I am just trying to understand how SQLite database works. So, here’s what I do: In the code section below which is taken from notepad tutorial 3rd exercise, I change KEY_TITLE to KEY_NAME and all place I find title to name. And the application crashes. Why does this happen?
public static final String KEY_TITLE = "title";
//change to: public static final String KEY_NAME = "name";
public static final String KEY_BODY = "body";
public static final String KEY_ROWID = "_id";
private static final String TAG = "NotesDbAdapter";
private DatabaseHelper mDbHelper;
private SQLiteDatabase mDb;
/**
* Database creation sql statement
*/
private static final String DATABASE_CREATE =
"create table notes (_id integer primary key autoincrement, "
+ "title text not null, body text not null);";
/*change to:
private static final String DATABASE_CREATE =
“create table notes (_id integer primary key autoincrement, ”
+ “name text not null, body text not null);”;
*/
It would be helpful if you copied the stack trace (using logcat / DDMS) or copied your entire SQLiteDBAdapter, but just looking at what you posted, you definitely have a problem in that you’re using the wrong field name in the sqlite database create statement.
The “title” field should be renamed “name” to match your changed column name.
Change:
To
I also tend to just use the statics themselves in the create statement, so it could be written like the following:
Then you could change the names often and not encounter database create breakage.