【问题标题】:Phonegap: Object xx has no method 'exec' at file:///android_asset/www/cordova.jsPhonegap:对象 xx 在 file:///android_asset/www/cordova.js 处没有方法“exec”
【发布时间】:2013-10-20 07:24:16
【问题描述】:

我在 Android 中开发了一个微型模块。当在 Eclipse 中使用 debug- 或 run 方法在我的“真实”设备上测试应用程序时,一切正常。 使用 Eclipse (Kepler)、PhoneGap 3.1 和 Android API 10 但是当我签署、导出、安装和运行应用程序时,一旦调用插件,我就会在调试器中看到以下错误:

file:///android_asset/www/cordova.js:第 863 行:未捕获的类型错误: 对象 org.apache.cordova.al@41ae5438 没有方法 'exec'

Uncaught TypeError: Object org.apache.cordova.al@41ae2400 has no 文件中的方法“执行”:///android_asset/www/cordova.js

我正在等待带有延迟对象的设备:

var def_deviceready = $.Deferred();
document.addEventListener("deviceready", deviceready, false);

function deviceready(){
    def_deviceready.resolve();
}
function dbaccess(query, arg, callback) {
    var dbaccess = cordova.require("cordova/plugin/dbaccess");
    $.when(def_deviceready).done(dbaccess.getData(query, arg, callback));
};

dbaccess.js:

cordova.define("cordova/plugin/dbaccess", function (require, exports, module) {
    var exec = require("cordova/exec");
    module.exports = {
            getData: function (query, arg, callback) {
                exec(callback, function(){ callback('callbackerror')}, "DBAccess", query, arg);
            }
    };
});

DBAccess.java:

public class DBAccess extends CordovaPlugin {

    HashMap<String, SQLiteDatabase> dbmap;

    /**
     * Constructor.
     */
    public DBAccess() {
        dbmap = new HashMap<String, SQLiteDatabase>();
    }
    @Override
    public boolean execute(String action, String arg, CallbackContext callbackContext) throws JSONException {
        Log.v("info", "This is what we got here: action=\'" + action +"\', arg=\'"+ arg +"\'.");
        if (action != null) {
            String Result = getData(action, arg);
            this.echo(Result, callbackContext);
            return true;
        }
        return false;
    }
.....
.....

...还有 config.xml 包含:

<feature name="DBAccess">
  <param name="android-package" value="com.phonegap.plugin.dbAccess.DBAccess"/>
</feature>

非常感谢任何帮助...

【问题讨论】:

    标签: java javascript android cordova phonegap-plugins


    【解决方案1】:

    您的脚本无法包含 dbaccess.js 尝试将其强制添加到 head 标记中。这就是为什么它无法执行该方法

    【讨论】:

      【解决方案2】:

      感谢 Vicky 的评论,我再次检查了整个项目(我已经包含了 dbaccess.js...)。

      我发现由于某种原因,AppLaud 将我的应用程序配置为使用 PhoneGap 3.0 运行,但它是使用 2.9 导出的,不同的 config.xml - 因此我的模块包含完全没有。我无法弄清楚不同版本/xml 文件的配置/定位位置或方式。

      所以我最终创建了一个全新的项目,将我的相关文件复制到相应的文件夹中,现在我开始运行了!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-20
        相关资源
        最近更新 更多