アセットフォルダーに事前に入力されたデータベースがあり、最初の実行時に内部ストレージに移動します。一部のデバイスでは問題なく動作しますが、一部のデバイスでは次のエラーが発生します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) {
}
}
}
なにが問題ですか?