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
Want to Compile Native Android Binary I Can Run in Terminal on the Phone
How to Use Roboto Font in Android Project
Android: Cloning a Drawable in Order to Make a Statelistdrawable with Filters
Download and Extract Zip File in Android
Android Studio Image Asset Launcher Icon Background Color
Why a Viewmodel Factory Is Needed in Android
Adding Custom Font to Theme in Android
Android Audiorecord Supported Sampling Rates
Manage Google Maps API Key with Gradle in Android Studio
Create a Chatview Layout in Android
Android Data Binding with a Custom View
Android Lollipop, Add Popup Menu from Title in Toolbar
Manually Adding Aar with Dependency Pom/Iml File
How to Set an Animated Gif File as Live Wallpaper in Android
Loading an Android Resource into a Webview
Error Building Player: Commandinvokationfailure: Unable to Convert Classes into Dex Format