Android上的SQLite Hangup

时间:2012-01-26 21:49:56

标签: android titanium-mobile

我不太了解这个问题,但它似乎与正在运行的SELECT查询相关联。如果我将该查询及其相关的逻辑块注释掉(如下所示),代码运行正常,但我没有得到内存中所需的值。如果我取消注释,我会得到像这个丑陋的家伙一样的百万错误:

D/dalvikvm(  556): GC_CONCURRENT freed 410K, 51% free 3172K/6407K, external 716K/1316K, paused 4ms+3ms

思想?

var SESSION = {
    i_company: '',
    s_username: ''
};

btn_signin.addEventListener('click', function(e) {
    btn_signin.title = 'Validating';

    var http = Titanium.Network.createHTTPClient();
    http.open('GET', VALIDATE_CREDENTIALS_URL);
    http.send({
        s_username: txt_username.value,
        s_password: txt_password.value
    });

    http.onerror = function() {
        alert('Unable to verify your credentials.');
    };

    http.onload = function() {
        var response = JSON.parse(this.responseText);

        if( response.s_status !== 'success' ) {
            btn_signin.title = 'Sign In';
            alert(response.data);
            return false;
        }

        btn_signin.title = 'Validated';

        // Store session
        var db = Titanium.Database.open('database');
        db.execute('DELETE FROM sessions');
        db.execute('INSERT INTO sessions (i_company, s_username) VALUES (?, ?)', response.data.i_company, response.data.s_username);

        btn_signin.title = 'Saving Session';

        // var db_rows = db.execute('SELECT i_company, s_username FROM sessions LIMIT 1');

        // while( db_rows.isValidRow() ) {
        //  SESSION.i_company = db_rows.fieldByName('i_company');
        //  SESSION.s_username = db_rows.fieldByName('s_username');
        // }
        db_rows.close();
        db.close();

        btn_signin.title = 'Loading App';

        // Focus on entry window
        tbg_app.open();
        wnd_signin.hide();
    };
});

1 个答案:

答案 0 :(得分:0)

将整个块放入try {}并捕获(Throwable e)。在调试器中逐步执行该块。找到异常上升的行。在catch区看看e。至于编程 - 你没有检查db_rows是否为null!这是错误