-1

我创建了一个包含 3 个表的数据库。检索数据库的内容并显示为 listview在模拟器中工作正常。但在设备中,列表视图为空。我用过“DBHelper”。为什么我无法查看设备中现有数据库的内容?

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();
}
4

1 回答 1

0

1)你把数据放在表里了吗?

于 2012-05-17T20:26:44.670 回答