未捕获的类型错误:对象 # 在 file:///android_asset/www/index.html 处没有方法“exec”
2024-01-07

  • 使用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 和行<plugin name="Notification" value="org.apache.cordova.Notification"/>存在
    • 检查index.html是否包含cordova-2.2.0.js
    • Case#1 打开index.html并修改为

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

to

<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

    • Case#2 打开index.html并修改为

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

to

<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 #<Object> has no method 'exec' at file:///android_asset/www/index.html:42 }

我确信我错过了一些东西......只是我无法断定它是什么。请帮帮我。


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

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

相反,这样做

document.addEventListener("deviceready", function() {
    showAlert('You are the winner!')
}, false)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

未捕获的类型错误:对象 # 在 file:///android_asset/www/index.html 处没有方法“exec” 的相关文章

随机推荐