我在资产文件夹中有一个预填充的数据库,我在第一次运行时将其移至内部存储。它在某些设备上运行良好,但在某些设备上出现以下错误:sqlite returned: error code = 1, msg = no such table: FTSgesla, db=/data/data/com.example.enigmar/databases/gesla
提到的表肯定存在,所以我不知道问题出在哪里。
SQLiteOpenHelper 代码:
public static class DictionaryOpenHelper extends SQLiteOpenHelper
{
private final Context mHelperContext;
private SQLiteDatabase mDatabase;
//private static String DB_PATH="/data/data/com.example.enigmar/databases/";
private static String DB_PATH="";
private static final String DB_NAME = "gesla";
DictionaryOpenHelper(Context context)
{
super(context, DB_NAME, null, 1);
//
DB_PATH = "/data/data/" + context.getPackageName() + "/databases/";
//
this.mHelperContext = context;
}
@Override
public void onCreate(SQLiteDatabase db)
{
}
public void createDataBase() throws IOException
{
boolean mDataBaseExist = checkDataBase();
if(!mDataBaseExist)
{
this.getReadableDatabase();
this.close();
new Thread(new Runnable()
{
public void run()
{
try
{
copyDataBase();
Log.e(TAG, "createDatabase database created");
BAZA_NAREJENA=true;
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
}).start();
}
}
private boolean checkDataBase()
{
File dbFile = new File(DB_PATH + DB_NAME);
return dbFile.exists();
}
private void copyDataBase() throws IOException
{
InputStream mInput = mHelperContext.getAssets().open(DB_NAME);
//final Resources resources = mHelperContext.getResources();
String outFileName = DB_PATH + DB_NAME;
OutputStream mOutput = new FileOutputStream(outFileName);
//InputStream mInput = resources.openRawResource(R.raw.gesla);
byte[] mBuffer = new byte[1024];
int mLength;
while ((mLength = mInput.read(mBuffer))>0)
{
mOutput.write(mBuffer, 0, mLength);
}
mOutput.flush();
mOutput.close();
mInput.close();
}
public boolean openDataBase() throws SQLException
{
String mPath = DB_PATH + DB_NAME;
mDatabase = SQLiteDatabase.openDatabase(mPath, null, SQLiteDatabase.CREATE_IF_NECESSARY);
return mDatabase != null;
}
@Override
public synchronized void close() {
if(mDatabase != null)
mDatabase.close();
super.close();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
}
怎么了?