我在这里搜索了一段时间,没有任何帮助。我想这很简单,我正在做一些愚蠢的事情。所以,我让这个 DataBaseHelper 创建一个表并在其上放置两个值:
public class DatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "db";
public static final String PROPERTY = "property";
public static final String VALUE = "value";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE configs (property VARCHAR(15), value VARCHAR(10));");
ContentValues cv=new ContentValues();
cv.put(PROPERTY, "registered");
cv.put(VALUE, "true");
db.insert("configs", PROPERTY, cv);
cv.put(PROPERTY, "test");
cv.put(VALUE, "test");
db.insert("configs", PROPERTY, cv);
}
}
在我的活动中,我正在尝试:
@Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
layout = (LinearLayout) findViewById(R.id.layoutRegister);
db = (new DatabaseHelper(this)).getWritableDatabase();
cursor = db.rawQuery("SELECT * FROM configs",
null);
if (cursor.moveToFirst()) {
debug = new TextView(this);
debug.setText(cursor.getString(cursor.getColumnIndex("property")));
layout.addView(debug);
}
}
它从不进入if。此外,当我尝试类似 cursor.getCount() 的东西时,我得到一个android.content.res.Resource$NotFoundException: String resource ID #0x0
我想这是一个简单的错误,但是......有什么帮助吗?=s