0

我试图更改使用 ContentProvider 存储数据的应用程序的现有代码,以使用带有 SQLCipher 的密码数据库。

这是我的 ContentProvider 代码:

import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteOpenHelper;
import net.sqlcipher.database.SQLiteQueryBuilder;
import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.SQLException;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;

public class DBAdapter extends ContentProvider {
static final String PROVIDER_NAME =
        "com.example.despensa.provider";
static final Uri CONTENT_URI =
        Uri.parse("content://"+ PROVIDER_NAME + "/items");

static final int ITEMS = 1;
static final int ITEMS_ID = 2;

private static final UriMatcher uriMatcher;
static{
    uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    uriMatcher.addURI(PROVIDER_NAME, "items", ITEMS);
    uriMatcher.addURI(PROVIDER_NAME, "items/#", ITEMS_ID);
}

static final String KEY_ROWID = "_id";
static final String KEY_NAME = "name";
static final String KEY_UNITS = "units";
static final String KEY_WEIGHT = "weight";
static final String TAG = "DBAdapter";

static final String DATABASE_NAME = "Pantry";
static final String DATABASE_TABLE = "items";
static final int DATABASE_VERSION =1;

static final String DATABASE_CREATE =
        "create table items (_id integer primary key autoincrement, "
        + "name text not null, units integer not null, weight integer);";

DatabaseHelper DBHelper;
SQLiteDatabase db;

@Override
public boolean onCreate() {

    Context context = getContext();

    SQLiteDatabase.loadLibs(context);
    DBHelper = new DatabaseHelper(context);
    db = DBHelper.getWritableDatabase("test123");

    return (db == null)? false:true;

}

private static class DatabaseHelper extends SQLiteOpenHelper
{
    DatabaseHelper(Context context)
    {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db)
    {
        try {
            db.execSQL(DATABASE_CREATE);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
    {
        Log.w(TAG, "Upgrading ....");
        db.execSQL("DROP TABLE IF EXISTS items");
        onCreate(db);
    }   
}
.....

但是当我运行代码时,我得到以下异常。

找不到从方法 com.example.despensa.DBAdapter.query 引用的类“net.sqlcipher.database.SQLiteQueryBuilder”

有什么建议吗?非常感谢你的帮助。托尼

4

0 回答 0