开发者

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).

The app works well in Chrome, but on an Android emulator the following error shows up in 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:

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 AUTOINCREMEN开发者_Go百科T,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. 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.


Can you share your app code in the app format with all the references to phonegap.js and so on ? Also I do not see your code using the window object. As per the phonegap apis the correct way to use the openDatabase() is var db = window.openDatabase(). Also, it would help if you could also mention the version of pg that you are using.


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)

please post more code

i think its the opendatabase that your using.


Override onExceededDatabaseQuota method in your WebChromeClient Object.

    @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);
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜