0

I have a database inside the assets folder. It works fine on Android 4.0, but on 2.2 or 2.1 it throws error while copying database. This is from the log:

Data exceeds UNCOMPRESS_DATA_MAX (1532928 vs 1048576)

Does this mean that the file is too big?

Code for OpenHelper:

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 final String DB_NAME = "gesla.db";

    DictionaryOpenHelper(Context context) 
    {
        super(context, DB_NAME, null, 1);
        this.mHelperContext = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db)
    {

    }

    public void createDataBase() throws IOException
    {

        boolean mDataBaseExist = checkDataBase();

        if(!mDataBaseExist)
        {
            this.getReadableDatabase();
            this.close();
            try 
            {
                copyDataBase();
                Log.e(TAG, "createDatabase database created");
            } 
            catch (IOException mIOException) 
            {
                throw new Error("ErrorCopyingDataBase");
            }
        }

    }

    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);

        String outFileName = DB_PATH + DB_NAME;

        OutputStream mOutput = new FileOutputStream(outFileName);

        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) {

    }

}
domen
  • 1,199
  • 3
  • 14
  • 26

1 Answers1

0

You can't store large files in assets folder (more than 1M). Split file in smaller parts or move it to raw folder. Here the explanation how to split file.

Community
  • 1
  • 1
Leonidos
  • 10,200
  • 2
  • 26
  • 37