Android 上的 SQLite 挂起
我不太明白这个问题,但它似乎与正在运行的 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();
};
});
I don't quite understand the issue, but it appears to be associated with the SELECT query being run. If I leave that query and its associated block of logic commented out (as shown below), the code runs fine, but I get none of the values I need in memory. If I uncomment it, I get a million errors like this ugly guy:
D/dalvikvm( 556): GC_CONCURRENT freed 410K, 51% free 3172K/6407K, external 716K/1316K, paused 4ms+3ms
Thoughts?
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();
};
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将整个块放入 try{} 和 catch(Throwable e) 中。在调试器中逐步执行该块。找到异常发生的行。查看 catch 块中的 e。至于编程 - 您没有检查 db_rows 是否为空!这里是一个错误。
Put the whole block into try{} and catch(Throwable e). Go the block step by step in debugger. Find the line where the exception rises. Look at e in catch block. As for programming - you are not checking db_rows for being null! It is an error here.