请帮助我这里是我的代码。在启动之前它不会显示任何错误。但是当我运行应用程序时,它不显示任何数据。当我检查数据库文件时,没有表 Created Kidly 帮帮我
感谢和问候 Gurmeet Singh
@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();
}
}
}