Fix: java.lang.NoClassDefFoundError
The “java.lang.NoClassDefFoundError no apparent reason” is a well-known error that can occur for one of two reasons. The first reason for which the “java.lang.NoClassDefFoundError no apparent reason” can occur is due to outdated Android Development Tools that need updating by the user. The more serious circumstance under which this error is known to occur is when a particular class, or the class on which a particular class relies, that was available to the program during compile time cannot be found by the program at run time.
This issue is just as problematic as it is common, with most Java programmers wanting to fix the issue as soon as it arises. Well, the following are two fixes that have worked for Android Development Tools users who have suffered from the issue in the past:
Method 1: Clean the project.
Back up the project that needs to be cleaned. While cleaning is generally pretty safe, prevention is always better than remedy.
1. Navigate to the “Project” section in the toolbar.
2. Select “Clean” from the dropdown menu.
3. In the window that subsequently opens, check “Clean projects selected below.
4. Select the projects that need cleaning.
5. Click on “OK.
Method 2: Check any unchecked libraries from the Build Path.
Find the folder where the .jar libraries are located. This folder should be named “libs.” If the folder is named “lib” instead, right-click on the folder, click on “Refactor,” and then choose “Rename.” Rename the folder to “libs.
Right-click on the project displaying the “java.lang.NoClassDefFoundError” error for no apparent reason, choose “Build Path,” and then select “Configure Build Path.
Navigate to the “Order and Export” tab.
Check the boxes beside any .jar libraries (such as “gcm.jar” and “libGoogleAnalyticsV2.jar”) that are not already checked.
Clean the project again.