使用PhoneGap的Andr​​oid的:不能在数据库中创建表 [英] Using PhoneGap for Android : Not able to create table in the database

查看:157
本文介绍了使用PhoneGap的Andr​​oid的:不能在数据库中创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:我是新来的PhoneGap,并试图创建使用HTML5 + PhoneGap的Andr​​oid上的SQLite的一个简单的表格

BackGround : I am new to PhoneGap and trying to create a simple table in the SQLite using HTML5 + PhoneGap on Android.

下面是我的HTML code。 (使用PhoneGap的网站参考code)

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.

找不到类的android.webkit.WebResourceResponse,引用
  从方法
  org.apache.cordova.CordovaWebViewClient.getWhitelistResponse

Could not find class 'android.webkit.WebResourceResponse', referenced from method org.apache.cordova.CordovaWebViewClient.getWhitelistResponse

类型错误:前pressionDB[空]的结果不是一个对象。在
  文件:///android_asset/www/index.html:25

TypeError: Result of expression 'db' [null] is not an object. at file:///android_asset/www/index.html:25

找不到类的android.webkit.WebResourceResponse,引用
  从方法
  org.apache.cordova.CordovaWebViewClient.getWhitelistResponse

Could not find class 'android.webkit.WebResourceResponse', referenced from method org.apache.cordova.CordovaWebViewClient.getWhitelistResponse

类型错误:前pressionDB[空]的结果不是一个对象。在
  文件:///android_asset/www/index.html:22

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 "

找不到类的android.webkit.WebResourceResponse,引用
  从方法
  org.apache.cordova.CordovaWebViewClient.getWhitelistResponse

Could not find class 'android.webkit.WebResourceResponse', referenced from method org.apache.cordova.CordovaWebViewClient.getWhitelistResponse

想要传达我没有改变我的config.xml并没有把任何条目列入白名单的条目,我不是说任何远程URL不知道天气这个错误可以忽略与否:?(

" 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 - 我与Android 2.3模拟器工作

谢谢
Gendaful

Thanks Gendaful

推荐答案

我得到了解决,我在这里张贴。

I got the solution and i am posting it here.

其实是越来越创建数据库,并正在/数据/数据​​/ PACKAGE_NAME /文件夹中。我是在'/数据/数据​​//数据库文件夹搜索它,这是我没能看到越来越创建该表的原因。

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.

<一个href=\"http://stackoverflow.com/questions/7499899/creating-sqlite-table-from-android-html-assets?rq=1\">Creating从SQLite表的Andr​​oid HTML资产

是很好的链接,并帮助了很多东西。

is good link and has helped a lot.

这篇关于使用PhoneGap的Andr​​oid的:不能在数据库中创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆