我的问题是我无法使用Cursor从数据库中检索数据,并且在所有情况下都会抛出SQLite异常
db.execSQL("CREATE TABLE BOOKS ("
+ "_ID INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "Name TEXT, "
+ "Sub_Field TEXT, "
+ "Cover INTEGER, "
+ "Priority INTEGER);");
ContentValues BookValue = new ContentValues();
BookValue.put("Name", "Cisco");
BookValue.put("Sub_Field", "Net");
BookValue.put("Cover", R.drawable.cappuccino );
BookValue.put("Priority", 1);
db.insert("BOOKS", null, BookValue);
MainActivity:
try {
SQLiteOpenHelper myDatabase = new myDatabase(this);
db = myDatabase.getWritableDatabase();
myText = (TextView) findViewById(R.id.txt);
cursor = db.query("BOOK", new String[] {"Name", "Sub_Field"}, null,null, null, null,null);
if (cursor != null) {
cursor.moveToFirst();
String name = cursor.getString(0);
myText.setText(name);
}
} catch (SQLiteException e ) {
myText = (TextView) findViewById(R.id.txt);
myText.setText("Try Again, you're soon to achieve your Goal...");
myText.setTextSize(20);
}
答案 0 :(得分:0)
在查询(选择)中,您的表名是“BOOK”,但您创建表“BOOKS”并将数据插入“BOOKS”