[英]Hardware-only 'Undefined' database error on openDatabase in Cordova 2.5 on Android - only for first attempt
Just updated my android app to Cordova 2.5 and, although it works beautifully in the emulator, it has developed a problem on my HTC desire such that I get a 'undefined' databse error when I try 刚刚将我的android应用程序更新为Cordova 2.5,尽管它在模拟器中可以很好地运行,但它对HTC的要求却产生了问题,以至于我尝试时遇到“未定义”的数据库错误
db = window.openDatabase("ProblemDirectoryDB", "1.0", "PhoneGap Demo", 100000);
However, if I open the same page a second time, it works fine and from then on, even after a forced stop and restart. 但是,如果我第二次打开同一页面,即使强制停止并重新启动后,它也可以正常工作。 I can recreate the error by deleting the application's data.
我可以通过删除应用程序的数据来重新创建错误。 The relevant code is below.
相关代码如下。 Any help/thoughts very gratefully received.
非常感谢您的任何帮助/想法。
var db;
var dbCreated = false;
function onBodyLoad(){
$.mobile.loadingMessageTextVisible = true;
$.mobile.loadingMessage = "Loading...";
$.mobile.showPageLoadingMsg();
if (!window.device){
document.addEventListener("deviceready", onDeviceReady, false);
}
else {
onDeviceReady();
}
}
function onDeviceReady() {
db = window.openDatabase("ProblemDirectoryDB", "1.0", "PhoneGap Demo", 100000);
if (dbCreated){
db.transaction(getProblems, read_transaction_error);
}
else{
db.transaction(populateDB, create_transaction_error, populateDB_success);
}
navigator.splashscreen.hide();
}
function populateDB_success() {
dbCreated = true;
db.transaction(getProblems, transaction_error);
}
function create_transaction_error(tx, error) {
$.mobile.hidePageLoadingMsg();
alert("Create Database Error: " + error);
}
Unbelievably, after hours and hours and a near-total rewrite, I finally spotted the 100000
bytes size
parameter in my window.openDatabase
call - my DB now exceeds 256K so simply changing it to 300000
appears to have solved my problem!! 令人难以置信的是,经过数小时和几乎全部的重写之后,我终于在
window.openDatabase
调用中发现了100000
字节size
参数-我的数据库现在超过256K,因此只需将其更改为300000
似乎就解决了我的问题! No wonder no-one else seems to have had the same problem - no-one else has been stupid enough not to notice the size parameter! 难怪没有其他人似乎也遇到过同样的问题-没有其他人愚蠢到没有注意到size参数! Although quite why it worked on the emulator and on second and successive opens on the hardware, I don't know.
尽管完全可以解释为什么它可以在模拟器上运行,并且可以在硬件上进行第二次和连续的打开,但是我不知道。 Anyway, problem solved.
无论如何,问题解决了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.