在android中创建新数据库时调用setLocale时出现问题
我第一次尝试一些数据库访问代码,但遇到一些错误,并且会 感谢一些帮助。这就是正在发生的事情:
1) 我通过调用此构造函数创建 SQLiteOpenHelper 的新实例:
public MyDbOpenHelper(Context context) {
super(context, "some_name.db", null, 1);
}
上面的实例是下面使用的变量 myHelper
2) 我正在调用 myHelper.getReadableDatabase()
3) 此时 Android 调用 my onCreate 方法。我对这个方法的实现 开始如下:
public void onCreate(SQLiteDatabase db) {
db.setLocale(new Locale("en"));
//...
}
4) 上面的调用没有完成。我得到以下转储:
开始交易失败设置区域设置
无法打开 some_name.db 进行写入(将尝试只读):
android.database.sqlite.SQLiteException:无法在事务内启动事务
位于 android.database.sqlite.SQLiteDatabase.native_setLocale(本机方法)
位于 android.database.sqlite.SQLiteDatabase.setLocale(SQLiteDatabase.java:1751)
位于 android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper...
在 android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper....
看起来像因为我试图在数据库尚不存在时获取可读的数据库,所以安卓 尝试创建它并为 setLocale 创建一个可写数据库...这就是为什么 它抱怨“交易中的交易”? 应该如何做?
谢谢,任何帮助将不胜感激
i'm trying some db access code for the first time and i'm getting some errors and would
appreciate some help. this is what is happening:
1) i'm creating a new instance of SQLiteOpenHelper by calling this constructor:
public MyDbOpenHelper(Context context) {
super(context, "some_name.db", null, 1);
}
the above instance is the variable myHelper used below
2) i'm calling myHelper.getReadableDatabase()
3) at this point Android calls my onCreate method. my implementation of this method
begins as follows:
public void onCreate(SQLiteDatabase db) {
db.setLocale(new Locale("en"));
//...
}
4) the above call does not complete. i get the following dump:
BEGIN TRANSACTION failed setting locale
couldn't open some_name.db for writing (will try read-only):
android.database.sqlite.SQLiteException: cannot start a transaction within a transaction
at android.database.sqlite.SQLiteDatabase.native_setLocale(Native Method)
at android.database.sqlite.SQLiteDatabase.setLocale(SQLiteDatabase.java:1751)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper...
at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper....
it looks like since i'm trying to get a readable db when the db does not yet exist, so Android
tries to create it and creates a writable db for the setLocale... and is that why
it complains about "transaction within transaction"?
how is it supposed to be done?
thanks, any help would be appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论