Делаю блокнот на android для практики с listview, адаптерами и SQLite. При использовании SimpleCursorAdapter возникает данная ошибка:
"Error Code : 1 (SQLITE_ERROR)
Caused By : SQL(query) error or missing database.
(no such table: NOTE_TABLE (code 1): , while compiling: INSERT INTO NOTE_TABLE (note_text) VALUES ('TEXT');)"
Подскажите в чем проблема.
Ниже ошибка и код классов.
public class ListActivity extends AppCompatActivity {
ListView notelistView;
SimpleCursorAdapter cursorAdapter;
SQLiteDatabase db;
SQLiteOpenHelper dbhelp;
DatabaseHelper helper;
Cursor listCursor;
String[] from;
int[] to;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
ListView noteList = findViewById(R.id.note_list);
dbhelp = new DatabaseHelper(this);
db = dbhelp.getReadableDatabase();
helper = new DatabaseHelper(this);
from = new String[] {helper.NOTE_TEXT};
to = new int[] {R.id.note_list};
db.rawQuery("INSERT INTO NOTE_TABLE (note_text) VALUES ('TEXT');", null);
listCursor = db.rawQuery("SELECT note_first_string FROM note_table",null); //ORDER BY _id
cursorAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, listCursor, from, to, 0);
noteList.setAdapter(cursorAdapter);
}
}
Класс-помощник
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "NOTE_DB";
public static int DATABASE_VERSION = 1;
public static String TABLE_NAME = "note_table";
public static final String NOTE_TEXT = "note_text";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.rawQuery("CREATE TABLE NOTE_TABLE (_id INTEGER PRIMARY KEY AUTOINCREMENT," + " note_text TEXT," + " note_first_string TEXT);", null);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}