Cordova Android ClassCastException

Solved!
Posted in General by Cesar Mon Jun 27 2016 20:27:49 GMT+0000 (UTC)·3·Viewed 668 times

Hello, I make a project with cordova. In iOS work fine, but y have this error in android: com.ionicframework.beacont520721 E/AndroidRuntime: FATAL EXCEPTION: main Process: com.ionicframework.beacont520721, PID: 2863 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ionicframework.beacont520721/com.ionicframework.beacont520721.MainActivity}: java.lang.ClassCastException: android.app.Application cannot be cast to com.innoquant.moca.phonegap.MOCApp at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) at android.app.ActivityThread.access$800(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to com.innoquant.moca.phonegap.MOCApp at com.innoquant.moca.phonegap.MOCAPlugin.initialize(MOCAPlugin.java:143) at org.apache.cordova.CordovaPlugin.privateInitialize(CordovaPlugin.java:57) at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:172) at org.apache.cordova.PluginManager.startupPlugins(PluginManager.java:98) at org.apache.cordova.PluginManager.init(PluginManager.java:87) at org.apache.cordova.CordovaWebViewImpl.init(CordovaWebViewImpl.java:116) at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:144) at org.apache.cordova.CordovaActivity.loadUrl(CordovaActivity.java:214) at com.ionicframework.beacont520721.MainActivity.onCreate(MainActivity.java:32) at android.app.Activity.performCreate(Activity.java:5990) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)  at android.app.ActivityThread.access$800(ActivityThread.java:151)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:135)  at android.app.ActivityThread.main(ActivityThread.java:5254)  at java.lang.reflect.Method.invoke(Native Method)  at java.lang.reflect.Method.invoke(Method.java:372)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)  What is the problem? Thanks
Ivan Gonzalez
June 28, 2016
Dear Cesar, Thank you for your message. In Android, MOCA Plugin needs to be started in a class that inherits from Application, and this class should be declared in the AndroidManifest.xml (reference: http://developer.mocaplatform.com/docs/moca-android-sdk-configuration#services--receivers) For the Cordova plugin, this is configured when the plugin is installed, however it not always possible to configure automatically it as it heavily depends on the project configuration itself. ###How to solve it Please go to the AndroidManifest.xml file of the Android project and add the following field to the `application` tag: android:name="com.innoquant.moca.phonegap.MOCApp" Example: ![](https://files.readme.io/F3KObXES3CnfPRbMGWbE_android-name-red.gif) If there is an existing class here, you will need to manually edit it and add the logic of the `com.innoquant.moca.phonegap.MOCApp` class, as you can only have one single class declared here. Please let us know if you have any issue with this, or send us an email to support@mocaplatform.com
Cesar
July 1, 2016
Yes, this solve all problems :)

Ivan Gonzalez marked this as solved
Markdown is allowed