Android SQLite 在模拟器中崩溃,但在手机中却没有?
我遇到一个有趣的问题,我的代码在手机上运行良好,但在模拟器上运行时,一旦应用程序尝试从数据库获取值,我就会崩溃。
这是导致它崩溃的 DB Helper 函数
/** Used to retrieve our lowest stored val */
public int GetLowestVal(){
// Get our databases results
Cursor result = null;
try {
// Get our databases results
result = super.getAll();
} catch( SQLException anyDbError ) {
// Errors? TODO
} finally {
// Finally TODO
}
// Setup initial lowest val
int lowestVal = 0;
// Move through results and compare them
while( result.moveToNext() ){
// Get our place from the DB
int index = Integer.parseInt(result.getString(1).trim());
// Last index should be lowest
if ( index == 10){
lowestVal = Integer.parseInt(result.getString(3).trim());
}
}
// Return our value
return lowestVal;
}
,它抛出的错误是:
递归调用 getWriteableDatabase()。
I'm having an interesting issue where my code runs fine on my phone, but when running on the emulator i get a crash as soon as the app tries to get a value from the database.
Here is the DB Helper function which is crashing it
/** Used to retrieve our lowest stored val */
public int GetLowestVal(){
// Get our databases results
Cursor result = null;
try {
// Get our databases results
result = super.getAll();
} catch( SQLException anyDbError ) {
// Errors? TODO
} finally {
// Finally TODO
}
// Setup initial lowest val
int lowestVal = 0;
// Move through results and compare them
while( result.moveToNext() ){
// Get our place from the DB
int index = Integer.parseInt(result.getString(1).trim());
// Last index should be lowest
if ( index == 10){
lowestVal = Integer.parseInt(result.getString(3).trim());
}
}
// Return our value
return lowestVal;
}
And the error it throws is:
getWriteableDatabase() was called recursively.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉,问题是我仍在尝试编辑
onCreate()
方法中的表,这会导致递归调用getWrteableDatabase()
。它在模拟器上不起作用但在手机上起作用的原因是,在将任何内容添加到
onCreate
之前就已经在手机上创建了数据库,但将其部署到其他设备上导致了崩溃。Sorry about that, the problem was that i was trying to edit the table still in the
onCreate()
method which causesgetWrteableDatabase()
to be called recursively.The reason it wasn't working on the emulator but worked on the phone was because the database had been created on the phone before anything was added to
onCreate
, but deploying it on other devices caused the crash.