无法解析 'USING A PRELOADED SQLITE DATABASE WITH SQLITEOPENHELPER' 示例中的符号 'context'

Cannot resolve symbol 'context' in 'USING A PRELOADED SQLITE DATABASE WITH SQLITEOPENHELPER' example

我正在使用这个 class java 从资产文件夹中读取数据库并复制到数据库文件夹。

在第 link 页中,它说:

To Use it ...

Just use it normally as you would use an ordinary SQLiteOpenHelper object.

Repository repo = Repository.getInstance( context ); SQLiteDatabase db = repo.getWritableDatabase(); ...

但在简单的新项目向导中 return 上下文参数错误。 有谁能帮帮我吗?

I'm using this class java to read db from assets folder and to copy to database folder.

我强烈建议您 use SQLiteAssetHelper,因为它是一个更成熟且经过测试的解决方案。

but in simple new projet wizard return error in context paramenter

Repository 构造函数采用 ContextActivity 继承自 Context。您正在尝试在 Activity 的方法中使用 Repository。因此,将 context 替换为 this.

Android活动继承Contextclass,所以可以按如下方式进行:

Repository.getInstance(this);