简体   繁体   English

Android的Cordova 2.5中openDatabase上的纯硬件“未定义”数据库错误-仅限首次尝试

[英]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.

相关问题 Android中的SQLite静态openDatabase数据库方法错误 - SQLite static openDatabase database method error in Android 无法仅在Android上使用Cordova读取undefined的handleEvent - Cannot read handleEvent of undefined with Cordova on Android only 仅带硬件键盘的Android EditText - Android EditText with hardware keyboard only Android HttpURLConnection连接错误仅在硬件设备上发生(在模拟器中不发生) - Android HttpURLConnection connecting error only on hardware devices (not in emulators) 无法读取android中未定义的属性'openDatabase' - Cannot read property 'openDatabase' of undefined in android 未捕获的TypeError:无法调用未定义的方法“ openDatabase”-仅从物理设备 - Uncaught TypeError: Cannot call method 'openDatabase' of undefined - only from physical device android中的数据库(openDatabase)文件在哪里? - Where database(openDatabase) file located in android? 有没有办法只为Android 4.0.3禁用硬件加速? - is there a way to disable hardware acceleration only for android 4.0.3? 仅Android上带有Google Analytics(分析)插件的PhoneGap / Cordova应用程序错误 - PhoneGap/Cordova Application with Google Analytics Plugin error on Android only openDatabase 在 Android PhoneGap 应用程序中创建错误 - openDatabase creates error in Android PhoneGap application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM