Android: Unable to instantiate application

前端 未结 11 1489
别跟我提以往
别跟我提以往 2021-01-03 23:40

I renamed my package and now I get this strange error:

Unable to instantiate application
app.MyApplication: java.lan         


        
11条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-04 00:08

    Let's assume, that your projects base package is really Application, as you've stated it in the manifest.

    If your MyApplication class is inside this package (the package declaration of the class is package Application;), then the application element in your androidManifest.xml should look like

    If this MyApplication class is inside the Application.app package (package Application.app;), then in the manifest you should write:

    If you didn't extend the android.app.Application (you don't have a MyApplication extends android.app.Application class), just wanted to set a name to your application, remove it this attribute, since it says to the compiler that there is an Application extension that should be instantiated instead of the default android.app.Application.

    And finally, if the first assumption is wrong, and you've changed for any reason the package declaration in your androidManifest's manifest element, undo it or update your classes to be in that package.

提交回复
热议问题