Android: Unable to instantiate activity / ClassNotFoundException

前端 未结 30 2816
粉色の甜心
粉色の甜心 2020-11-27 13:46

I recently published an app to the market and I\'m now getting an error by some user, the app presumably crashes right when it starts. Unfortunately I can\'t contact him dir

相关标签:
30条回答
  • 2020-11-27 14:14

    I had the same problem of you and, after hours of search, I discovered something interesting. I'll try to expose that as clearly as possible:

    • I created a project with a package called "myapp.sound" containing the activity. Program ran normally;
    • I renamed that package calling it "app.soundapp" and program still ran normally.

    However, in the manifest.xml file of the program there was something strange: the name of package was the old "myapp.sound". I changed manifest with correct new name and, from that moment on, our error occured. I don't know why, but seems that the "package name changer" of Eclipse doesn't update all the dependencies. If it's not strictly necessary, don't rename the package containing activity. Maybe, to solve your problem you have to create a new project and copy inside it all your java class.

    0 讨论(0)
  • 2020-11-27 14:14

    I solved this and could locate the causes: -The Manifest will be corrupt. Even if the package-structure is right and every single data was written down correctly the activity will not be found. -R will be in the package-structure which was first declared before renaming. -The run-configurations are setup with the wrong package of R. So the activity can't be found.

    What we have tried: -Manually editing the run-configs via export/import -Manually renaming the package-structure -Manually renaming the R-package-structure -Deleting the run-config (it will be rebuild if you try to start the app)

    Solution: Try to setup a new project without reusing your manifest. I have tried to reuse it and got the same problems all over again. So after the main cause has to be the corrupt manifest. I hope this helps!

    0 讨论(0)
  • 2020-11-27 14:16

    This error can also occur when you (at the project level) incorrectly Import > Android > Existing Android Code Into Workspace, via Eclipse. In my case, this resulted in an empty "src" folder, but then I noticed new folder starting with "java" at the root and continuing with the package path (i.e. com/zyzcorp/...), leading to the MainActivity.java file.

    To test what I thought may fix the problem, I copied the com.*.MainActivity.java file into the src folder, refreshed, cleaned, and restarted Eclipse. I was able to build and run the app on the target device.

    0 讨论(0)
  • 2020-11-27 14:16

    I had 5 different packages. And for some reason the compiler was looking for the activity on the wrong package.

    So I switched my activity and all the class that inherits the activity to the package that it was looking into.

    I got the name of the package it was looking for in the beginning of the logcat.

    0 讨论(0)
  • 2020-11-27 14:18

    Make sure your /src dir is listed in your projects>properties>java build path>source

    0 讨论(0)
  • 2020-11-27 14:18

    I has the same problem but this fixed it. In my androidmanifest.xml i had this line called android:name = myappnameActivity. Although my class name was just myappname. Hence i took off the Activity part in the xml file and all was fine.

    0 讨论(0)
提交回复
热议问题