Reputation: 278
I'm currently using PhoneGap 2.7.0 on my project and code runs without error on iOS.When I try to run the same code on android (with the exception of the Cordova javascript file, which I know is different for Android) I'm getting this error:
05-21 22:02:25.630 1663-1663/com.###.### D/Cordova: onPageFinished(file:///android_asset/www/index.html)
05-21 22:02:25.640 1663-1663/com.###.### D/CordovaLog: Uncaught Function required as first argument!
05-21 22:02:25.640 1663-1663/com.###.### E/Web Console: Uncaught Function required as first argument! at file:///android_asset/www/cordova-2.7.0.js:627
Here is the JavaScript I'm using in index.html:
<script type="text/javascript">
var app;
document.addEventListener("deviceready", function()
{
app = new AppWrapper();
}, false);
</script>
I'm not sure what the issue is.I had this issue before but it has resolved itself in the past (black magic?).Any help would be greatly appreciated.
Upvotes: 6
Views: 5021
Reputation: 41
Check if you had specified the right context of the callback function in your code.
Make sure that you don't use "this" in callback function. For example,
var app = {
init : function() {
document.addEventListener("deviceready", this.deviceready, false);
},
deviceready : function() {
app.appWrapper = this.createAppWrapper();//watch out who is "this", you should use "app" but not "this"
},
createAppWrapper : function() {
return new AppWrapper();
}
};
app.init();
Upvotes: 4
Reputation: 278
After employing Ripple to debug this issue (highly recommended), I found a pointer to an undefined function being applied to an event listener (so, not specific to the deviceready call).
For future developers: check to make sure all of your "addEventListener" calls are pointing to existing functions. Seems obvious, but it happens.
Upvotes: 14