【问题标题】:Uncaught TypeError: Object #<Object> has no method 'exec' at file:///android_asset/www/index.html未捕获的类型错误:对象 #<Object> 在 file:///android_asset/www/index.html 处没有方法 'exec'
【发布时间】:2012-11-25 18:49:49
【问题描述】:
  • 使用 PhoenGap 2.2.0
  • 执行\bin\create C:\Temp\Test com.test 测试
  • 有以下输出

Microsoft (R) Windows 脚本宿主版本 5.8 版权所有 (C) 微软公司。保留所有权利。

Creating new android project...
Building jar and js files...
Copying template files...
Copying js, jar & config.xml files...
Copying cordova command tools...
Updating AndroidManifest.xml and Main Activity...
  • 导入项目
    • 在 eclipse (4.2.0) 上做了
    • 文件 > 新建 > 项目 > Android > 来自现有代码的 Android 项目
    • 选择文件夹 C:\Temp\Test
    • 选中“将项目复制到工作区”
  • 进行更改
    • 检查 res\xml\config.xml 并且存在&lt;plugin name="Notification" value="org.apache.cordova.Notification"/&gt;
    • 检查 index.html 是否包含了 cordova-2.2.0.js
    • 案例#1 打开 index.html 并修改自

<script type="text/javascript"> app.initialize(); </script>

<script type="text/javascript">
function showAlert(msg){
navigator.notification.alert(msg);
}
document.addEventListener("deviceready", showAlert('You are the winner!'), false);
app.initialize();
</script>

我收到以下错误 11-25 10:29:58.399: E/Web Console(14604): Uncaught TypeError: Cannot call method 'alert' of undefined at file:///android_asset/www/index.html:40

    • 案例#2 打开 index.html 并修改自

<script type="text/javascript"> app.initialize(); </script>

<script type="text/javascript">
function successAlert(){}
function errorAlert(){}
function showAlert(msg){
cordova.exec(successAlert, errorAlert, "Notification","alert", [msg]);
}
document.addEventListener("deviceready", showAlert('You are the winner!'), false);
app.initialize();
</script>

我收到以下错误 11-25 10:25:06.575: E/Web Console(14149): Uncaught TypeError: Object #&lt;Object&gt; has no method 'exec' at file:///android_asset/www/index.html:42 }

我确定我错过了什么……只是我无法得出结论。请帮帮我。

【问题讨论】:

  • 仅供参考:使用 USB 部署时,我在实时设备上面临这些问题。我没有尝试过其他任何东西。安卓操作系统:4.2
  • 我有错误 --Uncaught TypeError: Object # has no method 'exec' -- 也找不到任何解决方案。我将“cordova-2.2.0.js”包含在“index.html”中并调用“nfc.addNdefListener(callback, [success], [error]);”在“phonegap-nfc.js”中实现。里面有“cordova.exec();”方法调用。我正在使用cordova 2.2.0 和phonegap-nfc 插件github.com/chariotsolutions/phonegap-nfc。但即使我直接在 index.html 中调用 exec 方法,它也无济于事。

标签: javascript android cordova phonegap-plugins


【解决方案1】:

这将立即调用showAlert,而不是延迟到事件触发时:

document.addEventListener("deviceready", showAlert('You are the winner!'), false)

改为这样做

document.addEventListener("deviceready", function() {
    showAlert('You are the winner!')
}, false)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-08
    • 2013-04-19
    • 2012-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多