-1
請幫助我這裏是我的代碼。在啓動之前,它不會顯示任何錯誤。但是 當我運行應用程序 它不顯示任何數據。 當我檢查數據庫文件沒有表創建 Kidly幫我數據庫不能正常工作
感謝&問候 古米特·辛格
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SQLiteDatabase myDB= null;
String TableName = "Dictionary";
String Data="";
try {
myDB = this.openOrCreateDatabase("Punjabishabdkosh", MODE_PRIVATE, null);
myDB.execSQL("CREATE TABLE IF NOT EXISTS "
+ TableName
+ " (Field1 VARCHAR, Field2 VARCHAR);");
myDB.execSQL("INSERT INTO "
+ TableName
+ " (Field1, Field2)"
+ " VALUES ('Gurmeet', Tiwana);");
Cursor c = myDB.rawQuery("SELECT * FROM " + TableName , null);
int Column1 = c.getColumnIndex("Field1");
int Column2 = c.getColumnIndex("Field2");
c.moveToFirst();
if (c != null) {
do {
String Name = c.getString(Column1);
int Age = c.getInt(Column2);
Data =Data +Name+"/"+Age+"\n";
}while(c.moveToNext());
}
TextView tv = new TextView(this);
tv.setText(Data);
setContentView(tv);
} catch(Exception e) {
Log.e("Error", "Error", e);
} finally {
if (myDB != null)
myDB.close();
}
}
}
在locgcat se如果有任何錯誤打印.. – bakriOnFire
您是否試圖從Field2檢索整數?您將Tiwana插入到Field2中,然後再嘗試使用不是整數的c.getInt(column2)。 – blaffie
請正確格式化您的代碼。使用縮進不正確來閱讀是非常困難的。 – Simon