Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android.app.Application cannot be cast to my application

I have few percent crashes when application from start points (launch activity, receivers) cannot be cast to my application.

My launch activity:

    override fun onCreate(savedInstanceState: Bundle?) {
        (application as MyApp)
        ...
    }

My app extends MultiDexApplication:

public class MyApp extends MultiDexApplication {
...

Crash log:

Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to com.my.myapp.MyApp
    at com.my.myapp.prelogin.presentation.LaunchActivity.onCreate(LaunchActivity.kt:59)
    at android.app.Activity.performCreate(Activity.java:6904)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
    at android.app.ActivityThread.access$1100(ActivityThread.java:229)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:7325)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

I spent a lot of time looking for this problem, but could not find a solution. I think it's trouble in android sdk.

p.s. I have name tag on manifest file

like image 287
Valery Boretsky Avatar asked Sep 05 '25 03:09

Valery Boretsky


1 Answers

Do this in your Manifest file

<application
        android:name="your.Packagename.CpuSpyApp"
like image 106
shadrack kipkoech Avatar answered Sep 07 '25 23:09

shadrack kipkoech