Android app ClassNotFoundException for main activity

后端 未结 12 639
灰色年华
灰色年华 2020-12-06 10:07

Most of the devices can run my app but I got this error report :

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.company.app/com         


        
相关标签:
12条回答
  • 2020-12-06 10:28

    Thanks to version control, I noticed that I didn't have these lines in my .classpath xml file:

    <classpathentry kind="src" path="src"/>
    <classpathentry kind="src" path="gen"/>
    

    These caused Class-not-found for main activity.

    0 讨论(0)
  • 2020-12-06 10:30

    I had this problem for the last couple days. I could run my app on every test environment, I could export a release apk, and install and run it on every test environment, but when I uploaded the apk to the play store and installed from the play store the app would fource close throwing ClassNotFoundException. It turned out that in my project I was sending multipart form data to a web api, and to do this requires some external libraries. At first I just included all the mim4j, httpclient, and httpcore .jars (turns out to be a lot of jars).

    After deleting almost all of them one by one and seeing if my project would still build I was left with only one jar THAT WAS ACTUALLY REQUIRED. The take away is delete any jars that are not required to build. Then I tested the app and turns out I needed to add one of the jars back because it's resources were referenced by the one that was required to build the project. Make sure to test every function of your app after deleting jars.

    Then I went through each library project I was including and went to right-click on project -> properties -> java build path -> order and export and checked all the boxes FOR EVERY LIBRARY and MY OWN PACKAGE.

    Then I did a project -> clean on every project that is included and the main project.

    Then I exported the apk and put the package up for beta testing and it finally worked on users devices.

    0 讨论(0)
  • 2020-12-06 10:31

    I've got the same when run Robolectric tests. Actually, test classpath includes jar with android.com.Activity, which has not been founded. A solution in my case is downgrade JAVA_HOME from 10th JDK version, which is used in Maven project.

    0 讨论(0)
  • 2020-12-06 10:34

    I had the same issue and the problem was a third party library that is using Android Support Library.

    myproject/libs/android-support-v4.jar 
    3rdpartylib/libs/android-support-v4.jar
    

    When I updated the library with newer version, the support library was also updated - but not in my project. After that I could not launch the application with this error. After making both libraries to be the same (copy), it was ok.

    0 讨论(0)
  • 2020-12-06 10:35

    I had exactly the same problem. Suddenly my app stopped working. I didint make any change to manifest, but with some accident there was missing first row:

    <?xml version="1.0" encoding="utf-8"?>

    This caused ClassNotFoundException for launcher activity. I was struggling with that for few hours and I overlooked this every time I was checking manifest for possible mistake.

    Strange thing happened after I have deleted this row again. Suprise, suprise app was still working. (and I didnt forget to rebuild app)

    Hope this help someone to save few hours.

    0 讨论(0)
  • 2020-12-06 10:37

    I just ran into this problem. Turns out it was because I had moved my MainActivity into a new package.

    What I did was move it from

    com.example.MainActivity
    

    into

    Activity
    

    so in my manifest it looked like this:

     android:name="Activity.MainActivity"`
    

    Solved it by moving it back into the original package. It can also be solved by renaming your packages correctly:

    Eg: com.example.Activity.MainActivity

    Hope this helps someone.

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