Hello! I'm new to programming, I hope for your advice. A simple application for notes. By clicking on fab there should be an entry in the database of 2 lines: the title (title) and the note itself (note). But the application crashes when you click on fab.
The method that makes the data in the database
fabOnCreatePage.setOnClickListener(new View.OnClickListener() { String title = editTitle.getText().toString(); String note = editNote.getText().toString(); SQLiteDatabase database = dataBase.getWritableDatabase(); ContentValues contentValues = new ContentValues(); @Override public void onClick(View view) { switch (view.getId()) { case R.id.fab_on_create_note: contentValues.put(DataBase.DB_TITLE, title ); contentValues.put(DataBase.DB_NOTE, note); database.insert(DataBase.DB_NAME, null, contentValues); break; } } } And itself bd (without onUpgrade)
public class DataBase extends SQLiteOpenHelper { public static final String DB_NAME = "db"; public static final int DB_VERSION = 1; public static final String DB_TITLE = "title"; public static final String DB_NOTE = "note"; public DataBase(Context context) { super(context, DB_NAME, null, DB_VERSION); } @Override public void onCreate(SQLiteDatabase sqLiteDatabase) { sqLiteDatabase.execSQL("create table notes(" + "_id integet primary key autoincrement, " + DB_TITLE + "text," + DB_NOTE + "text)"); } Error Message (I translated it, but still not clear)
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.idrisov.notes/com.example.idrisov.notes.CreateNote}: android.database.sqlite.SQLiteException: (code 1): , while compiling: create table notes(_id integet primary key autoincrement, titletext,notetext)
"text, which leads to the non - valid expression of creating a database - YuriySPb ♦_id,titletextandnotetextIn this case, the last two columns will be without affinity and you can write anything, just like the others ... And depending on what is written, it will be interpreted and interpreted accordingly. Illustration sqlfiddle.com/#!7/8c8ae/1 Columndis just the same and can contain bothtextandinteger. - Yura Ivanov