javascript - 未捕获的类型错误 : Object #<Object> has no method 'exec' at file:///android_asset/www/index. html

标签 javascript android cordova phonegap-plugins

  • 使用 PhoenGap 2.2.0
  • 执行\bin\create C:\Temp\Test com.test测试
  • 有以下输出

Microsoft (R) Windows Script Host Version 5.8 Copyright (C) Microsoft Corporation. All rights reserved.

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
    • 案例#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 #<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)

关于javascript - 未捕获的类型错误 : Object #<Object> has no method 'exec' at file:///android_asset/www/index. html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13554251/

相关文章:

javascript - 使用 fetch API 重写 jquery Ajax 调用

javascript - 如何阻止来自 javascript 计时器的消息重复?

android - 使用命令行参数启动phonegap/cordova应用程序?

android - Sencha Touch 1.1、PhoneGap 1.2、Android 文本区域/文本字段滚动问题

android - 为什么 AlarmManager 警报在第一次运行时延迟?

android - PhoneGap离线存储和压缩

javascript - 如何使用 firestore orderBy 但同时添加未定义的值

javascript - 为什么我的 javascript 不触发不同的 css3 动画延迟 Internet Explorer 10?

Android - 获取当前时间而不依赖于设备的时钟

android - Crashlytics 不推荐使用的方法 disabled()