Cordova Android Uncaught Function Error

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:

  • Why does Android Lint warn about String.format using default locale when explicitly using Locale.US?
  • How to listen to taps and get views using Accessibility in Android?
  • Fragment gets initialized twice when reloading activity with tabs when orientation changes
  • Size limitation on attached Parcelable?
  • Scala, Android and Eclipse
  • How to change target build on Android project?
  • <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.

    Related posts:

    How to get programmatically the data usage limit set by user on Android OS configuration?
    Android - Why use pending intents for geofences
    Button changes position when text in two lines
    &ldquo;android.view.View cannot be cast to android.view.ViewGroup&rdquo; exception
    Displaying multiple routes using Directions API in Android
    add android-support-v13.jar in Android Studio
  • How to turn on speaker for incoming call programmatically in Android L?
  • How do I intercept button presses on the headset in Android?
  • Slide right to left Android Animations
  • menu.findItem returns null
  • Android logcat error: ZipFileCache: init failed when open zip file - device specific?
  • Problem saving shared preferences in Android
  • 2 Solutions collect form web for “Cordova Android Uncaught Function Error”

    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.

    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();
    
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.