问题
BackGround : I am new to PhoneGap and trying to create a simple table in the SQLite using HTML5 + PhoneGap on Android.
Here is my HTML Code. (Using the reference code from PhoneGap site)
<html>
<head>
<title>Storage Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.7.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
function onDeviceReady() {
navigator.notification.alert(
'Welcome to SQLLiteDemo', // message
'', // callback
'Hey -- Welcome123' // title
);
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
db.transaction(populateDB, errorCB, successCB);
}
// Populate the database
//
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS DEMO');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
}
// Transaction error callback
//
function errorCB(tx, err) {
alert("Error processing SQL: "+err);
console.log('It is failure'+err);
}
// Transaction success callback
//
function successCB() {
console.log('It is success');
alert("success!");
}
</script>
</head>
<body>
<h1>Example</h1>
<p>Database</p>
</body>
</html>
I am not able to see the table getting created and getting the below errors on the console.
Could not find class 'android.webkit.WebResourceResponse', referenced from method org.apache.cordova.CordovaWebViewClient.getWhitelistResponse
TypeError: Result of expression 'db' [null] is not an object. at file:///android_asset/www/index.html:25
Could not find class 'android.webkit.WebResourceResponse', referenced from method org.apache.cordova.CordovaWebViewClient.getWhitelistResponse
TypeError: Result of expression 'db' [null] is not an object. at file:///android_asset/www/index.html:22
I am not sure what does this error "
Could not find class 'android.webkit.WebResourceResponse', referenced from method org.apache.cordova.CordovaWebViewClient.getWhitelistResponse
" wants to convey. I did not change my config.xml and did not put any entries in the whitelisted entries as I am not talking to any remote urls. Not sure weather this error can be ignore or not? :(
I am able to see the alert box using cordova, so there is not any issue related to integration with cordova but something weird is happening. Please help
P.S - I am working with Android 2.3 on Emulator.
Thanks Gendaful
回答1:
I could be off base, but it appears that window.openDatabase
is actually an HTML 5 feature of the browser. It looks like your code:
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
Is returning null
.
From your Android 2.3 emulator, launch the device's web browser and go to http://html5test.com/
, and see if web SQL database shows as supported.
回答2:
I got the solution and i am posting it here.
Actually, the DB is getting created and is under '/data/data/package_name/' folder. I was searching it under '/data/data//databases' folder and that is the reason I was not able to see the table getting created.
Creating SQLite Table from Android HTML Assets
is good link and has helped a lot.
来源:https://stackoverflow.com/questions/16740595/using-phonegap-for-android-not-able-to-create-table-in-the-database