Custom Global Application Class Breaks with "Android.App.Application Cannot Be Cast To"

Custom global Application class breaks with android.app.Application cannot be cast to

The error states that the type of the object returned by getApplication is android.app.Application. A possible cause for this is that you failed to define the application in the manifest. Make sure that your manifest includes something in the lines of:

<application android:name=".MyApp"...
</application>

Android - java.lang.classcastexception android.app.application cannot be cast

You can cast child class object to parent class object but you cannot do the reverse. You are trying to cast Application to ChuckApplication, which is not legal.

android.app.Application cannot be cast to LifecycleOwner

Why does android.app.Application not implement LifecycleOwner?

It does not have a lifecycle. It is created, then exists for the entire existence of the process.

Code where I try to use getApplication() as LifecycleOwner for LiveData:

Either use something with an actual lifecycle (activity, fragment, etc.) or use observeForever().

java.lang.ClassCastException: android.app.Application cannot be cast to roboguice.application.RoboApplication

Try this way

<application
android:name="roboguice.application.RoboApplication" // UPDATE HERE
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >

android.app.Application cannot be cast to class extending android.app.Application

Declare your class in AndroidManifest:

<application
android:name="your.package.AppExt"


Related Topics



Leave a reply



Submit