【问题标题】:Unable to invoke worklight adapter when invoked from android emulator从 android 模拟器调用时无法调用工作灯适配器
【发布时间】:2013-07-02 15:31:56
【问题描述】:

面对一个奇怪的问题,worklight 适配器无法从模拟器中调用。 LogCat 给出以下错误

07-02 20:56:59.063: D/DroidGap(873): onMessage(onNativeReady,null)
07-02 20:56:59.063: D/DroidGap(873): onMessage(onPageFinished,file:///data/data/com.PivMobileNew/files/www/default/PivMobileNew.html#clientListPage)
07-02 20:56:59.513: D/PivMobileNew(873):  --------- $('#clientListPage').bind('pageinit',  function(event){ ------------
07-02 20:57:00.673: E/PivMobileNew(873): [http://10.202.4.254:1028/worklight/apps/services/api/PivMobileNew/android/query] exception. undefined is not a function
07-02 20:57:00.823: D/CordovaLog(873): Uncaught TypeError: undefined is not a function
07-02 20:57:00.823: D/CordovaLog(873): file:///data/data/com.PivMobileNew/files/www/default/wlclient/js/worklight.js: Line 1467 : Uncaught TypeError: undefined is not a function
07-02 20:57:00.823: E/Web Console(873): Uncaught TypeError: undefined is not a function at file:///data/data/com.PivMobileNew/files/www/default/wlclient/js/worklight.js:1467

但是,在从 common 调用适配器时,它可以正常工作。

这是适配器调用代码...

function GetClient(strClientName) {
    var invocationData = {
            adapter : 'PivMobileAdapter'
                ,procedure : 'getClient'
                    ,parameters: [{"ClientName":strClientName}]
    };
    WL.Logger.debug(" --------- entered in function GetClient-------    2c");
    try {
    WL.Client.invokeProcedure(invocationData, {
        onSuccess : handleSuccess,
        onFailure : handleFailure,
    });
    }
    catch (e)
    {   WL.Logger.debug("---inside try catch, error occured while invokingProcedure----");
        WL.Logger.debug(e.message);
    }

    function handleSuccess(result) {
        WL.Logger.debug(" --------- inside handling success invoking procedure $('#searchNew').click(function() -------    2c");
        ...some code here1...
        ...some code here2...
    }

    function handleFailure(result) {
        WL.Logger.debug(" --------- inside handling failure invoking procedure $('#searchNew').click(function() -------    2c");
        ...some code here1...
        ...some code here2...
    }
}

不知道怎么走,有人可以帮忙吗?

【问题讨论】:

  • 使用调用适配器过程的 JavaScript 编辑您的问题。
  • 似乎在抱怨找不到handleSuccess和handleFailure内部函数。
  • 我认为app事件没有到达过程调用部分;请添加启动应用程序时获得的整个 logcat。

标签: android ibm-mobilefirst worklight-adapters


【解决方案1】:

在使用引用之前,您必须定义 onSuccess 和 onFailure 处理函数。 您还需要将函数引用保存在变量中,因为您的代码已经在函数中。

var handleSuccess = function(xxx) {
    // some code
};

var handleFailure = function(xxx) {
    // some code
};
// references need to exist prior to passing them as callback handlers.
WL.Client.invokeProcedure(invocationData, {
        onSuccess : handleSuccess,
        onFailure : handleFailure,
});

【讨论】:

  • 试过这个,移动了上面的函数定义,但仍然无法正常工作。回调函数是否需要像'handleSuccess'这样的引号?
  • 我再次更新了我的答案。你确定你的 JavaScript 函数被调用了,还是在你的应用调用它时已经包含在内?
  • 这也没有帮助。但我遇到了问题。
  • 感谢大家的帮助。
  • 在清单文件中添加互联网权限并将设备连接到互联网,在 Worklight 服务器的同一网络中
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-16
  • 1970-01-01
  • 2016-09-13
  • 2012-11-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多