0

我遇到了一个有趣的问题,我的代码在手机上运行良好,但是在模拟器上运行时,一旦应用程序尝试从数据库中获取值,我就会崩溃。

这是导致它崩溃的 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() 被递归调用。

4

1 回答 1

0

对此感到抱歉,问题是我试图在onCreate()导致getWrteableDatabase()被递归调用的方法中编辑表。

它不能在模拟器上工作但在手机上工作的原因是因为在添加任何内容之前已经在手机上创建了数据库onCreate,但是在其他设备上部署它会导致崩溃。

于 2011-02-04T01:55:24.293 回答