NoClassDefFoundError for code in an Java library on Android

前端 未结 24 1645
梦如初夏
梦如初夏 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:42

    The NoClassDefFoundError description is, from the SO tag:

    The Java Error thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found. The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.

    Or better:

    NoClassDefFoundError in Java comes when Java Virtual Machine is not able to find a particular class at runtime which was available during compile time.

    from this page. Check it, there are some ways to solve the error. I hope it helps.

    0 讨论(0)
  • 2020-11-22 15:44

    If none of the above works (like it happened to me), and you're using as a library another project in Eclipse.

    Do so: Right click project -> Properties -> Android -> Library -> Add

    That did it for me! Adding a project as a library (Project Properties)

    0 讨论(0)
  • 2020-11-22 15:46

    Solutions:

    1. List item
    2. Check Exports Order
    3. Enable Multi Dex
    4. Check api level of views in layout. I faced same problem with searchView. I have check api level while adding searchview but added implements SearchView.OnQueryTextListener to class file.
    0 讨论(0)
  • 2020-11-22 15:47

    I have just figured out something with this error.

    Just make sure that the library jar file contains the compiled R class under android.support.v7.appcompat package and copy all the res in the v7 appcompat support "project" in your ANDROID_SDK_HOME/extras/android/support/v7/appcompat folder.

    I use Netbeans with the Android plugin and this solved my issue.

    0 讨论(0)
  • 2020-11-22 15:47

    1)In Manifest file mention your activity name and action for it and also category . 2)In your Activity mention your starting contentview and mention your view id's in the activity.

    0 讨论(0)
  • 2020-11-22 15:48

    jars used to be in the lib/ folder, now they're in libs/ If you use lib, you can move your jars from lib to libs, and remove the dependencies from project properties/java build path because Android will now find them automatically.

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