10
  • using PhoenGap 2.2.0
  • Executed \bin\create C:\Temp\Test com.test Test
  • Had following output

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...
  • Imported Project
    • On eclipse (4.2.0) did
    • File > New > Project > Android > Android Project from Existing Code
    • Selected the folder C:\Temp\Test
    • Checked "Copy project into workspace"
  • Making changes
    • Checked res\xml\config.xml and the line <plugin name="Notification" value="org.apache.cordova.Notification"/> is present
    • Checked that index.html has the cordova-2.2.0.js included
    • Case#1 Opened index.html and modified from

<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>

I get following error 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 Opened index.html and modified from

<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>

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.

javadevg
  • 644
  • 1
  • 7
  • 13
  • Just an FYI: I'm facing these problems on live device when deployed using USB. I haven't tried anything else. Android OS : 4.2 – javadevg Nov 25 '12 at 19:36
  • I have the error --Uncaught TypeError: Object # has no method 'exec'-- as well and can't find any solution. I included "cordova-2.2.0.js" into my "index.html" and calling "nfc.addNdefListener(callback, [success], [error]);" implemented in "phonegap-nfc.js". In there is the "cordova.exec();" method called. I'm using cordova 2.2.0 and the phonegap-nfc plugin https://github.com/chariotsolutions/phonegap-nfc. But it's nowhere working even if i'm calling the exec method directly in index.html. – Yves Jan 07 '13 at 20:53

1 Answers1

11

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

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

Instead do this

document.addEventListener("deviceready", function() {
    showAlert('You are the winner!')
}, false)
AndiDog
  • 68,631
  • 21
  • 159
  • 205