简体   繁体   English

openDatabase 在 Android PhoneGap 应用程序中创建错误

[英]openDatabase creates error in Android PhoneGap application

I built a basic phone app using HTML5 and JavaScript (including JQTouch), and then used PhoneGap to turn it into an Android app (after many traumas - seems that PhoneGap and Windows computers don't get along too well). I built a basic phone app using HTML5 and JavaScript (including JQTouch), and then used PhoneGap to turn it into an Android app (after many traumas - seems that PhoneGap and Windows computers don't get along too well).

The app works well in Chrome, but on an Android emulator the following error shows up in LogCat:该应用程序在 Chrome 中运行良好,但在 Android 模拟器上,LogCat 中显示以下错误:

06-07 21:38:51.711: DEBUG/WebCore(204): Console: ReferenceError: Can't find variable: openDatabase line: 9 source: file:///android_asset/www/handicap.js

This refers to the following line in handicap.js:这指的是 handicap.js 中的以下行:

db = openDatabase('Handicaps', '1.0', 'Handicaps', 65536);

The wider context of this piece of code is:这段代码的更广泛的上下文是:

// initialise all important functions
$(document).ready(function(){
$('#newrace form').submit(saveRace);
$('#newrace form').submit(setTitle);
$('#enterhandicaps form').submit(savePrediction);
$('#enterhandicaps form').submit(refreshEntries);
$('#calcraces').click(raceList);
// create database to hold data on predicted and actual times
db = openDatabase('Handicaps', '1.0', 'Handicaps', 65536);
db.transaction(
    function(transaction) {
        transaction.executeSql(
            'CREATE TABLE IF NOT EXISTS predictions (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,racename TEXT NOT NULL, runner TEXT NOT NULL, prediction INTEGER, start TEXT, finish TEXT, position TEXT);'
        );
        transaction.executeSql(
            'CREATE TABLE IF NOT EXISTS races (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,racename TEXT NOT NULL, date TEXT, distance REAL);'
        );
        transaction.executeSql(
            'CREATE TABLE IF NOT EXISTS autocompletion (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,runner TEXT NOT NULL, value TEXT,racename TEXT NOT NULL);'
        );
    }
);
}
);

On looking at other people having similar problems on stackoverflow, I've tried the suggestion of using only Android versions below 2.2 but that has not helped.在查看其他在 stackoverflow 上遇到类似问题的人时,我尝试了仅使用低于 2.2 的 Android 版本的建议,但这并没有帮助。 Any other suggestions?还有其他建议吗? Could be something very obvious that I've missed, as I'm completely new to this.可能是我错过的非常明显的事情,因为我对此完全陌生。 The complete code for the app in web browser form is at https://github.com/fhr/Handicap-timer-app if that helps. web 浏览器表单中应用程序的完整代码位于https://github.com/fhr/Handicap-timer-app如果有帮助的话。

Can you share your app code in the app format with all the references to phonegap.js and so on?您能否以应用程序格式分享您的应用程序代码以及对 phonegap.js 等的所有引用? Also I do not see your code using the window object.此外,我没有看到您使用 window object 的代码。 As per the phonegap apis the correct way to use the openDatabase() is var db = window.openDatabase() .根据 phonegap api,使用 openDatabase( openDatabase()的正确方法是var db = window.openDatabase() Also, it would help if you could also mention the version of pg that you are using.此外,如果您还可以提及您正在使用的 pg 版本,这将有所帮助。

Override onExceededDatabaseQuota method in your WebChromeClient Object.覆盖 WebChromeClient Object 中的 onExceededDatabaseQuota 方法。

    @Override
    public void onExceededDatabaseQuota(String url, String databaseIdentifier,
            long currentQuota, long estimatedSize, long totalUsedQuota,
            WebStorage.QuotaUpdater quotaUpdater) {
        Log.d("test", "onExceededDatabaseQuota : " + "  currentQuota=" + currentQuota
                + "   estimatedSize=" + estimatedSize + "   totalUsedQuota=" + totalUsedQuota);
        quotaUpdater.updateQuota(estimatedSize * 2);
    }

well i think its trying to open the file "file:///android_asset/www/handicap.js" as opposed to where a db normally is //data/data//database/dbfile (normally no extension)好吧,我认为它试图打开文件“file:///android_asset/www/handicap.js”,而不是数据库通常是//data/data//database/dbfile(通常没有扩展名)

please post more code请发布更多代码

i think its the opendatabase that your using.我认为它是您使用的开放数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM