ICC function error from Cordoba Android

I am currently using PhoneGap 2.7.0 for my project, and the code works without errors in iOS. When I try to run the same code on Android (except for the javascript file from Cordoba, which I know is different for Android) I get 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 am not sure what the problem is. I had this problem before, but in the past it was resolved (black magic?). Any help would be greatly appreciated.

+6
source share
2 answers

After using Ripple to debug this problem (highly recommended), I found a pointer to the undefined function applied to the event listener (so this does not apply to the deviceready call).

For future developers: make sure all of your addEventListener calls point to existing functions. It seems obvious, but it does.

+14
source

Make sure you specify the correct callback function context in your code.

Make sure you are not using "this" in the callback function. For instance,

 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(); 
+4
source

Source: https://habr.com/ru/post/945525/


All Articles