未捕获的TypeError:Object#< Object>在file:///android_asset/www/index.html没有方法'exec'

问题描述:


  • 使用PhoenGap 2.2.0

  • 已执行\ bin \\ \\创建C:\ Temp \ Test.com.test测试

  • 有以下输出


Microsoft(R)Windows Script Host Version 5.8
版权所有(C)Microsoft Corporation。保留所有权利。

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 =通知value =org.apache.cordova.Notification/> 存在

      • Checked res\xml\config.xml and the line <plugin name="Notification" value="org.apache.cordova.Notification"/> is present

      • 检查index.html是否包含cordova-2.2.0.js


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

      < script type =text / javasc RIPT&GT;
      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控制台(14604):未捕获的TypeError:无法在file:///android_asset/www/index.html调用未定义的方法'alert':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控制台(14149):未捕获的TypeError:对象#<对象>在文件中没有方法'exec':///android_asset/www/index.html:42
      }

      I get following error 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 }

      我'我肯定错过了一些东西......只是因为我无法得出结论。请帮帮我。

      I'm sure that I missed something...just that I'm not able to conclude what is it. Please help me out.

这将立即调用 showAlert 延迟事件发生时:

This will call showAlert immediately, instead of delaying to when the event fires:

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

取而代之的

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