NoClassDefFoundError for code in an Java library on Android

前端 未结 24 1919
梦如初夏
梦如初夏 2020-11-22 15:19

I am experiencing an error quite often among my users. The app crashes during startup. When the MainActivity is supposed to be loaded the VM apparently cannot find the class

24条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 15:51

    I had the same issue, I did the following to fix the problem.

    1. Go to "Properties" of the project.
    2. Select "Java Build Path"
    3. Select "Order and Export" Tab
    4. You should see the selected project's "src" and "gen" paths and dependencies here.
    5. The order how they listed were first "src" and then "gen" path
    6. I switch them, so that "gen" folder is build before the "src"

    gen - automated code in project (from dependencies and references)
    src - source code in project

    There was no need to restart the Eclipse. It just started working.

    Honestly I have never tried "Android Tools > Fix Project Properties", sometimes it might be doing the same thing. I do not know, I just did above after seen the error message, thinking something is wrong with the build paths.


    Edit


    Later on it was not sufficient, I was getting the error again. Then I "checked" all the dependencies listed in that view. Now it works again. So far so good. I will keep this updated if it fails again.

    FYI: in my last attempt, I tried "Android Tools > Fix Project Properties", but it didn't work out for me.

提交回复
热议问题