0

In PhoneGap how do I create/open a database in Android?

I am using this code to create a database:

function onDeviceReady() {
        alert("okey");
        var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
 }

then, in console it prints this error message:

E/Web Console(13516): TypeError: Result of expression 'db' [null] is not an object. at file:///android_asset/www/index.html:24

How can I remove this problem?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
MRT
  • 1,610
  • 15
  • 41

1 Answers1

1

I think your problem is with scope of db variable. Try this

var db;
function onDeviceReady() {
        alert("okey");
        db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
 }
hkutluay
  • 6,794
  • 2
  • 33
  • 53
  • I have created sample code with your function and it run on chrome with no error. Could you update your post with whole of your code? – hkutluay Apr 07 '12 at 09:08
  • [check this](http://stackoverflow.com/questions/10031757/how-i-create-open-database-in-android) this is my example code it run on iphone properly but not android >>>> 'db' [null] is not an object. at file:///android_asset/www/index.html >>>> this error is show – MRT Apr 07 '12 at 09:28
  • your code looks correct. Did you checked AndroidManifest.xml configuration? I suggest that remove the phonegap referance and try to open this html on android browser. (put html page a web server and check it still has a same error to identify issue html or not) – hkutluay Apr 07 '12 at 09:40
  • can u elaborate this, or how i check androidManifest.xml config, – MRT Apr 07 '12 at 09:46
  • androidmanifest.xml file must be same as phonegap required to run phonegap properly. check http://phonegap.com/start/#android. – hkutluay Apr 07 '12 at 09:51