in my app i am trying to fetch some data from database and i am showing it in a list. When i run the app in my Motorola(2.1) and in Samsung Ace(2.3) and i some of my emulators t
you try this code
try {
db = this.openOrCreateDatabase("chaek.db", MODE_PRIVATE, null);
db.close();
openDatabase();
createTable();
} catch (SQLException se) {
Toast.makeText(this, se.getMessage(), 1).show();
}
private void openDatabase() {
try {
db = SQLiteDatabase.openDatabase("/data/data/com.pack.store/databases/chaek.db",
null, SQLiteDatabase.CREATE_IF_NECESSARY);
//Toast.makeText(this, "DB was opened!", 1).show();
} catch (SQLiteException e) {
Toast.makeText(this, e.getMessage(), 1).show();
}
}// createDatabase
public class BaseDAO extends OrmLiteSqliteOpenHelper {
public static Dao<?, Integer> instanseDao(Context cont, Class c,String Dbname) {
File path=new File(DATABASE_PATH);
File f = new File(DATABASE_PATH+DB_NAME);//改默认数据库目录需先手动创建数据库文件
if (!path.exists()) {
path.mkdirs();// 创建一个目录
}
if (!f.exists()) {
try {
f.createNewFile();//创建文件
} catch (IOException e) {
e.printStackTrace();
}
}
//how do??????
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(f,null);//创建数据库实例
BaseDAO baseDAO = new BaseDAO(cont);
//baseDAO.onCreate(db);
//baseDAO.onUpgrade(db,baseDAO.getConnectionSource(), OLD_DB_VERSION, DB_VERSION);
//baseDAO.close();//注意要先关掉
//db =SQLiteDatabase.openDatabase(DATABASE_PATH+DB_NAME, null, SQLiteDatabase.CREATE_IF_NECESSARY);
try {
Dao = baseDAO.getDao(c);
} catch (SQLException e) {
e.printStackTrace();
}
CONT=cont;
C=c;
DB_NAME = Dbname;
return Dao;
}