我有一个有线问题。我写了一个使用 sqlite 的代码。这是相关的行:
private final String DB_NAME = "cus";
private final String TABLE_NAME = "cus2";
SQLiteDatabase customersDB2 = null;
/** Called when the activity is first created. */
private void mFillDbsTable(){
try {
customersDB2.execSQL("INSERT INTO " + TABLE_NAME + " Values ( 1, 'the ', 'ה- ');");
customersDB2.execSQL("INSERT INTO " + TABLE_NAME + " Values ( 2, 'of ', 'של ');");
customersDB2.execSQL("INSERT INTO " + TABLE_NAME + " Values ( 3, 'to ', 'אל ');");
customersDB2.execSQL("INSERT INTO " + TABLE_NAME + " Values ( 4, 'and ', 'ו - ');");
customersDB2.execSQL("INSERT INTO " + TABLE_NAME + " Values ( 5, 'a ', 'מופיע לפני שם עצם ביחיד ללא הא הידיעה ');");
customersDB2.execSQL("INSERT INTO " + TABLE_NAME + " Values ( 6, 'in ', 'בתוך ');");
customersDB2.execSQL("INSERT INTO " + TABLE_NAME + " Values ( 7, 'for ', 'עבור ');");
................
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_learn);
try {
customersDB2 = this.openOrCreateDatabase( DB_NAME, MODE_PRIVATE, null);
customersDB2.execSQL("CREATE TABLE " +
TABLE_NAME +
" (Block INT," +
" Name VARCHAR, Street VARCHAR);");
mFillDbsTable();
}catch (SQLiteException se ) {
Log.e(getClass().getSimpleName(), "create/Open the database problem");
}
现在,当我询问查询时:
correctAnswer=oneTOfour.nextInt(4);
Toast.makeText(this,"correctAnswerק"+correctAnswer,Toast.LENGTH_SHORT).show();
correctAnswerTHE_ANSWER =(r.nextInt(1000)) + 1;
Toast.makeText(this,"correctAnswerTHE_ANSWER"+correctAnswerTHE_ANSWER,Toast.LENGTH_SHORT).show();
ArrayList<String> results = new ArrayList<String>();
Cursor c = customersDB2.rawQuery("SELECT Name, Street FROM " +
TABLE_NAME +
" where Block = 66 ", null);
if (c != null ) { //true
Toast.makeText(this,"c.getColumnIndex(Name)" + c.getColumnIndex("Name"),Toast.LENGTH_SHORT).show(); //got 0!!
if (c.moveToFirst()) {
do {
name = c.getString(c.getColumnIndex("Name"));
street = c.getString(c.getColumnIndex("Street"));
results.add(name + ", " + street );
}while (c.moveToNext());
}
}
else{
Toast.makeText(this,"null2",Toast.LENGTH_SHORT).show();
}
question.setText(name); //this is null
}
它没有达到第二个如果
也许我第一次运行这个应用程序时只有 2 列。我试图打开其他项目,更改表的名称..没有任何工作。一些想法?