- 使用 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"/>
在场
- 检查了 res\xml\config.xml 和行
- 检查 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/