-1
我創建了一個帶有3個表格的數據庫。數據庫內容的檢索和顯示爲列表視圖在模擬器中正常工作。但在設備中,列表視圖是空的。 我用過「DBHelper」。爲什麼我無法查看設備中現有數據庫的內容?android數據庫
public class DatabaseHelper{
private static final String TAG = "DBAdapter";
public static final String column_1="CategoryName";
public static final String row_id="_id";
public static final String wordcolumn="word";
public static final String row_idword="_id";
public static final String row_idfor="CategoryId";
private DatabaseHelperDB dDbhelper;
private SQLiteDatabase dDb;
private DatabaseAdapter dbAdapt;
private static final String Database_CreateCat="create table if not exists categorys (_id integer primary key, CategoryName text not null);";
private static final String Database_CreateWord="create table if not exists wordss (_id integer primary key autoincrement, "
+ "CategoryId integer, word text not null, foreign key(CategoryId) references categorys(_id));";
private static final String Database_Name="idea_generator_db2_1";
private static final String Database_TableCat="categorys";
private static final String Database_TableWord="wordss";
private final Context dctx;
private static final int database_version=1;
public DatabaseHelper(Context ctx)
{
this.dctx=ctx;
dDbhelper=new DatabaseHelperDB(ctx);
}
private static class DatabaseAdapter extends SQLiteOpenHelper
{
DatabaseAdapter(Context context)
{
super(context,Database_Name,null,database_version);
}
public void onCreate(SQLiteDatabase db)
{
try{
db.execSQL(Database_CreateCat);
db.execSQL(Database_CreateWord);
//db.execSQL(sql)
}catch(SQLException e)
{
e.printStackTrace();
}
}
public void onUpgrade(SQLiteDatabase db,int oldversion,int newversion)
{
Log.w(TAG, "Database upgradation from version "+oldversion+" to "+newversion);
db.execSQL("DROP TABLE IF EXISTS "+Database_TableCat);
db.execSQL("DROP TABLE IF EXISTS "+Database_TableWord);
onCreate(db);
}
}
public DatabaseHelper open()throws SQLException{
dDbhelper= new DatabaseHelperDB(dctx);
dDb=dDbhelper.getWritableDatabase();
return this;
}
public void close()
{
dDbhelper.close();
}
你有什麼在你的logcat? – CaseyB
也許一個愚蠢的問題,但你有沒有把數據放入你的數據庫? – Barak