У меня есть база данных, которая находится в активах / database /.Я пользуюсь библиотекой android-sqlite-asset-helper Пробовал архивировать базу данных, не помогло.Вылазит ошибка все равно
E/SQLiteAssetHelper: Couldn't open databases/brodsky.db for writing (will try read-only):
com.readystatesoftware.sqliteasset.SQLiteAssetHelper$SQLiteAssetException: Missing databases/databases/brodsky.db file (or .zip, .gz archive) in assets, or target folder not writable
at android.content.res.AssetManager.openAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:336)
at android.content.res.AssetManager.open(AssetManager.java:310)
at com.readystatesoftware.sqliteasset.SQLiteAssetHelper.copyDatabaseFromAssets(SQLiteAssetHelper.java:436)
at com.readystatesoftware.sqliteasset.SQLiteAssetHelper.createOrOpenDatabase(SQLiteAssetHelper.java:400)
at com.readystatesoftware.sqliteasset.SQLiteAssetHelper.getWritableDatabase(SQLiteAssetHelper.java:176)
at com.readystatesoftware.sqliteasset.SQLiteAssetHelper.getReadableDatabase(SQLiteAssetHelper.java:254)
at rodionova.lyubov.brodsky.db.PoemsProvider.query(PoemsProvider.java:40)
at android.content.ContentProvider.query(ContentProvider.java:1140)
at android.content.ContentProvider$Transport.query(ContentProvider.java:262)
at android.content.ContentResolver.query(ContentResolver.java:506)
DbHelper:
public class PoemsDbHelper extends SQLiteAssetHelper {
private static String DB_NAME = "databases/brodsky.db";
private static final int DB_VERSION = 1;
public PoemsDbHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
}
ну и класс ContentProvider, как это также указано в ошибках в логах
публичный класс PoemsProviderextends ContentProvider {частный статический финал UriMatcher URI_MATCHER = новый UriMatcher (UriMatcher.NO_MATCH);private static final int POEMS = 1;private static final int POEM = 2;приватный статический финал int FACTS = 3;private static final int BIOGRAPHY = 4;
static {
URI_MATCHER.addURI(PoemsContract.AUTHORITY, "poems", POEMS);
URI_MATCHER.addURI(PoemsContract.AUTHORITY, "poems/#", POEM);
URI_MATCHER.addURI(PoemsContract.AUTHORITY, "facts", FACTS);
URI_MATCHER.addURI(PoemsContract.AUTHORITY, "biography", BIOGRAPHY);
}
private PoemsDbHelper poemsDbHelper;
@Override
public boolean onCreate() {
poemsDbHelper = new PoemsDbHelper(getContext());
return true;
}
@Nullable
@Override
public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection,
@Nullable String[] selectionArgs, @Nullable String sortOrder) {
SQLiteDatabase db = poemsDbHelper.getReadableDatabase();
switch (URI_MATCHER.match(uri)) {
case POEMS:
if (TextUtils.isEmpty(sortOrder)) {
sortOrder = PoemsContract.Poems.COLUMN_ID + " DESC";
}
return db.query(PoemsContract.Poems.TABLE_NAME,
projection,
selection,
selectionArgs,
null,
null,
sortOrder);
case POEM:
String id = uri.getLastPathSegment();
if (TextUtils.isEmpty(selection)) {
selection = PoemsContract.Poems._ID + " = ?";
selectionArgs = new String[]{id};
} else {
selection = selection + " AND " + PoemsContract.Poems._ID + " = ?";
String[] newSelectionArgs = new String[selectionArgs.length + 1];
System.arraycopy(selectionArgs, 0, newSelectionArgs, 0, selectionArgs.length);
newSelectionArgs[newSelectionArgs.length - 1] = id;
selectionArgs = newSelectionArgs;
}
case FACTS:
if (TextUtils.isEmpty(sortOrder)) {
sortOrder = PoemsContract.Facts.COLUMN_ID + " DESC";
}
return db.query(PoemsContract.Facts.TABLE_NAME,
projection,
selection,
selectionArgs,
null,
null,
sortOrder);
case BIOGRAPHY:
if (TextUtils.isEmpty(sortOrder)) {
sortOrder = PoemsContract.Biography.COLUMN_ID + " DESC";
}
return db.query(PoemsContract.Biography.TABLE_NAME,
projection,
selection,
selectionArgs,
null,
null,
sortOrder);
default:
return null;
}
}