Android ClassNotFoundException: Didn't find class on path - java
10-22 15:29:40.897: E/AndroidRuntime(2561): FATAL EXCEPTION: main
10-22 15:29:40.897: E/AndroidRuntime(2561): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.gvg.simid/com.gvg.simid.Login}: java.lang.ClassNotFoundException: Didn't find class "com.gvg.simid.Login" on path: DexPathList[[zip file "/data/app/com.gvg.simid-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.gvg.simid-1, /vendor/lib, /system/lib]]
10-22 15:29:40.897: E/AndroidRuntime(2561): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
10-22 15:29:40.897: E/AndroidRuntime(2561): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
10-22 15:29:40.897: E/AndroidRuntime(2561): at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-22 15:29:40.897: E/AndroidRuntime(2561): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-22 15:29:40.897: E/AndroidRuntime(2561): at android.os.Handler.dispatchMessage(Handler.java:99)
10-22 15:29:40.897: E/AndroidRuntime(2561): at android.os.Looper.loop(Looper.java:137)
10-22 15:29:40.897: E/AndroidRuntime(2561): at android.app.ActivityThread.main(ActivityThread.java:5103)
10-22 15:29:40.897: E/AndroidRuntime(2561): at java.lang.reflect.Method.invokeNative(Native Method)
10-22 15:29:40.897: E/AndroidRuntime(2561): at java.lang.reflect.Method.invoke(Method.java:525)
10-22 15:29:40.897: E/AndroidRuntime(2561): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-22 15:29:40.897: E/AndroidRuntime(2561): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-22 15:29:40.897: E/AndroidRuntime(2561): at dalvik.system.NativeStart.main(Native Method)
10-22 15:29:40.897: E/AndroidRuntime(2561): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.gvg.simid.Login" on path: DexPathList[[zip file "/data/app/com.gvg.simid-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.gvg.simid-1, /vendor/lib, /system/lib]]
10-22 15:29:40.897: E/AndroidRuntime(2561): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
10-22 15:29:40.897: E/AndroidRuntime(2561): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
10-22 15:29:40.897: E/AndroidRuntime(2561): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
10-22 15:29:40.897: E/AndroidRuntime(2561): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
10-22 15:29:40.897: E/AndroidRuntime(2561): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
10-22 15:29:40.897: E/AndroidRuntime(2561): ... 11 more
I'm not really sure what is causing it as it is correctly listed in the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gvg.simid"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.READ_OWNER_DATA" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_OWNER_DATA" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-feature android:name="android.hardware.usb.host" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.gvg.simid.Login"
android:label="#string/app_name"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I also added "Android Private Libraries" to build path, and moved it to the top of "Order and Export", but it still gave me the same error.
EDIT: I rebuilt the project completely, and was unable to reproduce the error. Not sure what was causing it.
I had the same issue for my project. It happened due to the conflict in android support library version between my project and the library project that I added in my project. Put the same version android support library in your project and library projects you included and clean build... Everything will work...
This following method worked for me
Right click on your project and select properties
The "Properties for " panel will open. From the menu on the left go to Java Build Path -> Order and Export
From the list below uncheck the box next to "Android Dependencies"
Finally clean your project and run
For those of you who are having this issue on Android Studio, I had the same problem after a merge and for some reason it even persisted after clean and invalidate cash/restart operations which was driving me crazy.
Turns out, it can be fixed by running gradle build once from command line. Simply run the following n the project directory:
./gradlew assemble clean
./gradlew assemble
I hope it'd save someone the time waste and frustration I had to go through.
I had same issue, this worked for me
1) Full path of activity in mainfest in place of relative path.
2) Delete 'build' folder and clean project.
If you added a new Library Project as a module to your Android project and you're using Kotlin in your library do not forget to add
apply plugin: 'kotlin-android'
to top of your module's Gradle file. Android Studio does not add this line when you created a new module and this may waste your hours like me.
Edit: After a while, I just struggled with this problem again and this time I forgot to add my module as a dependency on the project. :)
If you are using Eclipse try Project -> Clean
This happens if we change Build Path of the APP, this can be in any case of Adding or Removing or Changing Libraries or .jar file. The Best solution is to Restart the Eclipse.
If you get this error while using the new Instant Run feature in Android Studio 2.0 and above then this is some kind of bug on their side.
To fix this you will have to stop your app manually on Device/Emulator if it's not stopped then from Android Studio select Build→Rebuild Project.
Then click the Run button or SHIFT+F10
For any one who is having multidex enable write this
inside build.gradle
apply plugin: 'com.android.application'
android {
defaultConfig {
multiDexEnabled true
}
dexOptions {
javaMaxHeapSize "4g"
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:multidex:1.0.1'
}
write a class EnableMultiDex like below
import android.content.Context;
import android.support.multidex.MultiDexApplication;
public class EnableMultiDex extends MultiDexApplication {
private static EnableMultiDex enableMultiDex;
public static Context context;
public EnableMultiDex(){
enableMultiDex=this;
}
public static EnableMultiDex getEnableMultiDexApp() {
return enableMultiDex;
}
#Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
}
}
and in AndroidManifest.xml write this className inside Application tag
<application
android:name="YourPakageName.EnableMultiDex"
android:hardwareAccelerated="true"
android:icon="#drawable/wowio_launch_logo"
android:label="#string/app_name"
android:largeHeap="true"
tools:node="replace">
In my case it was proguard minification process that removed some important classes from my production apk.
The solution was to edit the proguard-rules.pro file and add the following:
-keep class com.someimportant3rdpartypackage.** { *; }
If you are using Multidex on Android 4.4 and prior, your issue might be that your activity class is located in the second dex file and therefore not found by the android system.
To keep your activity class in the main dex file, see this page:
https://developer.android.com/studio/build/multidex.html#keep
To find which classes are located in a dex file use Android Studio.
Simply drag n drop your apk into Android Studio. You should be able to see your dex files in the apk explorer.
Then select the dex file to see what classes are inside.
another alternative is dexdump:
You can check the content of your dex files contained in your apk by using the command dexdump which can be found in
android-sdk/build-tools/27.0.3/dexdump
For windows users see this tool I made to ease the process
I faced this error once when I defined a class that extended a view but referred to this custom view in the layout file with the wrong name. Instead of <com.example.customview/>, I had included <com.customview/> in the XML layout file.
1) Create libs folder under project root
2) Copy and paste the jar file into it
3) Configure the build path (Add jar)
4) Clean and run
cheers :-)
Believe me or not... I tried out almost each answer I had found here on stackoverflow. Nothing would help, until I just restarted the machine. My Android Studio works on Ubuntu 16.04 LTS.
I faced the same problem and solved it by doing the following:
From the build menu select
1- clean Project.
2- Build APK.
I met the same problem and I noticed the sample code was put under directory "java" instead of directory "src".
After moving the code to src, the problem was solved.
Also make sure the app directory is split into multiple folders.
e.g. /main/com/site/appname/ not /main/com.site.appname/
Hope it works~
I face the same problem , and after a lot of work and search , I figured out the solution : I just cleaned the project then build the apk.
-Build->Clean Project
-Build-> Build APK(s)
I hope it is useful.....
I had this issue recently and I am using Android Studio 0.8.4
The problem was the fact that I decided to rename an XML menu layout file that was called main.xml.
Right click on it and chose Refactor --> Rename. Before renaming it, be sure uncheck "Search in comments and strings" and pressed Refactor.
Because my file was originally named 'main', it renamed critical paths in the app.iml and build.gradle, mainly the java.srcDirs in the build.gradle, since the path is defined as 'src/main/java'.
I hope this helps anyone that may be experiencing this issue.
I had this problem after upgrading from version 18.
After the upgrade I had the following:
Project Build Target was 5.01, targetSDKVersion=21
But:
Build Tools were still from Android 4.3.1 (18)
What I noticed was that those apps that were deriving their activities from ActionBarActivity crashed with the above error those that did not still ran.
So the simple fix was to use the latest Android SDK Build Tools 21.1.2
instead of only those of Android SDK Build Tools 18, which seems somehow the default.
So the culprit seems the Appcompat library, which I use for Actionbar backward compability.
And a by the way: using the appcompat library I had to set/fix:
$SDKInstallDIR$\Android\android-sdk\extras\android\support\v7\appcompat\project.properties
target=android-21 (which was recommended in some other useful post and which has a value of 19 by default))
I had this problem several times and often I didn't do something obviously wrong with dependencies.
It's always a good idea to check if this 'not found' class is present in the final apk. If it is, like it happened in my cases, the problem usually is:
It's not that given class is not found, but it cannot be loaded because its super class is missing.
Check if class that you extend is available and then try to fix your build script or dependencies accordingly.
I had the same issue on Windows. I had renamed the path to the project to something containing a space.
Make sure the path to your project does not contain a space.
Solution mentioned here --> Multidex Issue solution worked for me. Below is what needs to be added to Application context :
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
I had this issue, raised by several causes, but i see this in your stacktrace "**Unable to instantiate activity ComponentInfo{...}: java.lang.ClassNotFoundException: Didn't find class "..." on path: DexPathList[[**", I found a diference in my .classpath before it stop working.
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
I've ADDED the line:
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
this is the final version:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
Now it works! =)
I had the same exact issue. As #weiweia suggested, move the code from the java directory to src worked for me. I also removed the Android Dependencies from Project --> Properties --> Java Build Path --> Order and Export, and made sure only to include Library Projects in the Android screen.
I had this problem for quite a while, and like everybody else the answers above didn't apply to my project.
In my project I had linked up a project to my project and it was throwing ClassDefNotFoundError every time some code for the other project was executed.
So this was my solution. I went to project properties of my project and Java Build Path. Pressed the "Source"-tab and "link source" from src-folder of the other project to my own project and named a new folder "core-src".
Hopes this solution helps someone
I had the same issue. I am using Xamarin.Android.
The problem in my case was that I changed the versionCode and versionName.
I had no problem when I had them set like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="pac.ka.ge" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
The issue appeared when I changed it to this (versionCode 2 and versionName 0.0.1):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package=" pac.ka.ge " android:versionCode="2" android:versionName="0.0.1" android:installLocation="auto">
I fixed the issue by changing to versionCode 2 and versionName 1.0.0.1, like so:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package=" pac.ka.ge " android:versionCode="2" android:versionName="1.0.0.1" android:installLocation="auto">
I am unsure why this was a problem, maybe Android doesn't like a lower versionName with a higher versionCode?
I found the following on http://developer.android.com/guide/topics/manifest/manifest-element.html#vname
android:versionCode
An internal version number. This number is used only to determine whether one version is more recent than another, with higher numbers indicating more recent versions. This is not the version number shown to users; that number is set by the versionName attribute.
The value must be set as an integer, such as "100". You can define it however you want, as long as each successive version has a higher number. For example, it could be a build number. Or you could translate a version number in "x.y" format to an integer by encoding the "x" and "y" separately in the lower and upper 16 bits. Or you could simply increase the number by one each time a new version is released.
android:versionName
The version number shown to users. This attribute can be set as a raw string or as a reference to a string resource. The string has no other purpose than to be displayed to users. The versionCode attribute holds the significant version number used internally.
Just in case anybody faces the same problem as me and no suggest
answer here helps.
For me the cause was, that the Android studio refactor is buggy.
I moved an innerclass outside of a class, which was a View and therefore
also had a xml, where the direct path was set. This path will not get
refactored by studio! And no error will be thrown.
Hope this helps anybody. Cheers.
In our case we wanted to compile Vagrant version and had same error. We fixed it by clean project and rebuild project in Build menu
I just restarted the device and ran the app. It worked without any issues. Hope this helps someone :)
I found this error in Android Studio when i tried do debug in a device with API 23, so i checked the Android Studio and i noticed that i didnt had instaled this API 23 version. After install, i solved the problem.
Related
Unresolved Class 'FileProvider' in manifest.xml (Android Java)
I am building my first Java application. Its functionality includes taking camera images and saving them along with saving 'Project' information locally for said images to be associated with. I believe I need to include the FileProvider to my code: <provider android:name="android.support.v4.content.FileProvider" android:authorities="devkit.blade.vuzix.com.blade_template_app" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="#xml/provider_path"></meta-data> </provider> In the above XML .FileProvider is not resolving and so I cant build the app. What's the problem here? Also for context #xml/provider_path references this file: <?xml version="1.0" encoding="utf-8"?> <paths> <external-path name="/storage/emulated/0" path="."/> </paths>
I believe I need to include the FileProvider to my code In your <provider> element in your manifest, try changing android.support.v4.content.FileProvider (the fully-qualified class name to an old edition of FileProvider) to androidx.core.content.FileProvider.
Adding this to my build.grade (app module) allowed it to be referenced correctly. If you are required to use API level 27 (pre androidX) this is the way! implementation 'com.android.support:support-core-utils:27.0.0'
JRebel will not hot deploy source files with embedded tomcat in intellij
I have the following project structure project-root --core ---build.gradle ---project.gradle --web ---build.gradle ---project.gradle I configured jRebel to run with gradle, so I can start my embedded tomcat 8 with the command gradle tomcatRun This shows log-output of jrebel and my application starts on the embedded server, but there is no hot deployment when i change java files. With the IntelliJ JRebel Plugin I created the rebel.xml files for each of the project project-root, core and web. Also I added a rebel.xml inside the web project in the folder web/build/classes/main as described here Normally jrebel should show at startup that its wachting some folders, but this is not the case on my site, so i guess there is something wrong with my configuration here the rebel.xml files project-root (Path c:/project-root/rebel.xml) <?xml xsd...."> <classpath> <dir name="c:/project-root/out/production/classes"> </dir> </classpath> </application> core (Path c:/project-root/core/src/main/resources/rebel.xml) <?xml version="1.0" encoding="UTF-8"?> <application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_1.xsd"> <classpath> <dir name="c:/project-root/core/out/production/resources"> </dir> <dir name="c:/project-root/core/out/production/classes"> </dir> </classpath> </application> web (Path c:/project-root/web/src/main/resources/rebel.xml) <?xml version="1.0" encoding="UTF-8"?> <application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_1.xsd"> <classpath> <dir name="c:/project-root/web/out/production/classes"> </dir> </classpath> </application> web (Path c:/project-root/web/build/classes/main/rebel.xml) <?xml version="1.0" encoding="UTF-8"?> <application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd"> <classpath> <dir name="c:/project-root/web/build/classes/main"> </dir> </classpath> <web> <link target="/"> <dir name="c:/project-root/web/src/main/webapp"> </dir> </link> </web> </application> To attach jrebel to my gradle i did the following batch calls before starting gradle tomcatRun set REBEL_HOME=C:\Users\myuser\.IdeaIC2017.3\config\plugins\jr-ide-idea\lib\jrebel6 set JAVA_OPTS="-agentpath:%REBEL_HOME%\lib\jrebel64.dll" then calling gradlew tomcatRun starts the tomcat and jrebel gradlew tomcatRun 2018-01-09 10:24:09 JRebel: Starting logging to file: C:\Users\myuser\.jrebel\jrebel.log 2018-01-09 10:24:09 JRebel: 2018-01-09 10:24:09 JRebel: ############################################################# 2018-01-09 10:24:09 JRebel: 2018-01-09 10:24:09 JRebel: JRebel Agent 7.1.3 (201711301108) 2018-01-09 10:24:09 JRebel: (c) Copyright ZeroTurnaround AS, Estonia, Tartu. 2018-01-09 10:24:09 JRebel: 2018-01-09 10:24:09 JRebel: Over the last 2 days JRebel prevented 2018-01-09 10:24:09 JRebel: at least 0 redeploys/restarts saving you about 0 hours. But when I change some source files, nothing is detected by jrebel, also when i manually called gradlew compileJava
I think that the problem is that JRebel is not attached to the actual process running the embedded Tomcat server. Instead, it gets attached to the Gradle's wrapper process. Try attaching JRebel's JVM argument via the org.gradle.jvmargs option instead. gradle tomcatRun -Dorg.gradle.jvmargs="-agentpath:/path/to/jrebel/lib/libjrebel64.so" Additionally, since tomcatRun task makes use of exploded deployment, rebel.xml files will not be necessary. This is because the build output directory is the same as the deployment directory and the changes made in that directory are automatically picked up by JRebel and reloaded. Make sure to also compile the changes that you made using the gradle compileJava command to do so. I tried it out personally and it seems to work well. Although it does not output the JRebel banner to the console output, it does let you know when a class file was reloaded.
While the answer by Tiit is correct, I would like to add that when using Gretty, you need to specify the -agentpath:/path/to/jrebel/lib/libjrebel64.so argument in your build.gradle file like so: gretty { . . . jvmArgs = [ '-agentpath:/path/to/jrebel/lib/libjrebel64.so' ] } otherwise, by using -Dorg.gradle.jvmargs option, JRebel agent seems to attach to a wrong process when using Gretty launcher.
Resources referenced from the manifest cannot vary by configuration
When I want to insert the follow meta-tag: <meta-data android:name="com.android.systemui.action_assist_icon" android:resource="#mipmap/ic_launcher" /> I get the error message: Resources referenced from the manifest cannot vary by configuration (except for version qualifiers, e.g. -v21.) Found variation in hdpi, mdpi, xhdpi, xxhdpi, xxxhdpi How can I fix this?
Variation of resources in AndroidManifest.xml is detected as error. It may be ignored like this: <?xml version="1.0" encoding="utf-8"?> <manifest ... xmlns:tools="http://schemas.android.com/tools" ...> ... <meta-data android:name="com.android.systemui.action_assist_icon" android:resource="#mipmap/ic_launcher" tools:ignore="ManifestResource" /> ... </manifest> see: Android : Facebook app id showing error in values-ta/strings.xml and can't able to generate signed apk
I moved such strings to globalstrings.xml and removed the references from the locale files.
Gradle can't build Android Project in command line, aapt fails
I have created a basic Android project following this guide. Now when I run gradle(version 2.10) in my command line I get the following error: FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':processDebugResources'. > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/opt/android-sdk/build-tools/23.0.2/aapt'' finished with non-zero exit value 1 This is my build.gradle file: buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.5.0' } } apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.2" } And here is my AndroidManifest.xml file: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.hello" android:versionCode="1" android:versionName="1.0.0" > <application android:label="#string/app_name" > <activity android:name=".HelloActivity" android:label="#string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> Funny thing is, when I start Android Studio(1.5) and build a test application there it works fine, but doing it in command-line fails. I tried copying the gradle file from AS, to no avail. I checked the installation path, aapt is where it is supposed to be. I'm quite lost here since I used that very same guide from above a few months ago. Today I updated my Android SDK installation(EDIT: I made sure the right revisions are installed) but I can't get anything to build properly. Let me know if you need more information, I'm stuck.
I figured it out myself. After reinstalling Gradle, I finally got a new error message that told me in plain english what was wrong(it was a problem with my resources). This is really weird, since I use Archlinux and all other Gradle updates worked fine before. Thanks anyway to whomever has given this some thought :)
java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
While running junit test in eclipse I am getting this Exception: java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing I've added junit.jar library file. I've tried different versions of junit.jar: 4.4, 4.8, etc. How do I fix this Exception?
Add hamcrest-all-X.X.jar to your classpath. Latest version as of Feb 2015 is 1.3: http://code.google.com/p/hamcrest/downloads/detail?name=hamcrest-all-1.3.jar&can=2&q=
According to the JUnit GitHub team website (https://github.com/junit-team/junit/wiki/Download-and-Install), junit.jar and hamcrest-core.jar are both needed in the classpath when using JUnit 4.11. Here is the Maven dependency block for including junit and hamcrest. <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.1.2</version> <scope>test</scope> </dependency> <!-- Needed by junit --> <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-all</artifactId> <version>1.3</version> <scope>test</scope> </dependency>
A few steps you have to follow: Right click on the project. Choose Build Path Then from its menu choose Add Libraries. Choose JUnit then click Next. Choose JUnit4 then Finish.
Works for me: IntelliJ IDEA 13.1.1, JUnit4, Java 6 I changed the file in project path: [PROJECT_NAME].iml Replaced: <library> <CLASSES> <root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.11.jar!/" /> </CLASSES> <JAVADOC /> <SOURCES /> </library> By: <library name="JUnit4"> <CLASSES> <root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.11.jar!/" /> <root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-core-1.3.jar!/" /> <root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-library-1.3.jar!/" /> </CLASSES> <JAVADOC /> <SOURCES /> </library> So the final .iml file is: <?xml version="1.0" encoding="UTF-8"?> <module type="JAVA_MODULE" version="4"> <component name="NewModuleRootManager" inherit-compiler-output="true"> <exclude-output /> <content url="file://$MODULE_DIR$"> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" /> </content> <orderEntry type="inheritedJdk" /> <orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="module-library"> <library name="JUnit4"> <CLASSES> <root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.11.jar!/" /> <root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-core-1.3.jar!/" /> <root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-library-1.3.jar!/" /> </CLASSES> <JAVADOC /> <SOURCES /> </library> </orderEntry> </component> </module> P.S.: save the file and don't let to IntelliJ Idea reload it. Just once.
You need junit-dep.jar because the junit.jar has a copy of old Hamcrest classes.
Just in case there's anyone here using netbeans and has the same problem, all you have to do is Right click on TestLibraries Click on Add Library Select JUnit and click add library Repeat the process but this time click on Hamcrest and the click add library This should solve the problem
This problem is because of your classpath miss hamcrest-core-1.3.jar. To resolve this add hamcrest-core-1.3.jar as you add junit-4.XX.jar into your classpath. At first, I encounter this problem too, but after I refer to the official site and add hamcrest-core-1.3.jar into classpath with command line, it works properly finally. javac -d ../../../../bin/ -cp ~/libs/junit-4.12.jar:/home/limxtop/projects/algorithms/bin MaxHeapTest.java java -cp ../../../../bin/:/home/limxtop/libs/junit-4.12.jar:/home/limxtop/libs/hamcrest-core-1.3.jar org.junit.runner.JUnitCore com.limxtop.heap.MaxHeapTest
You need to add the hamcrest-core JAR to the classpath as described here: https://github.com/junit-team/junit4/wiki/Download-and-Install
As a general rule, always make sure hamcrest is before any other testing libraries on the classpath, as many such libraries include hamcrest classes and may therefore conflict with the hamcrest version you're using. This will resolve most problems of the type you're describing.
the simplest way of solving the problem to begin with is copying latest version of hamcrest-code.jar into your CLASSPATH that is the file you store other .jar files needed for compilation and running of your application. that could be e.g.: C:/ant/lib
It sounds like a classpath issue, so there are a few different ways to go about it. Where does org/hamcret/SelfDescribing come from? Is that your class or in a different jar? Try going to your project Build Path and on the Libraries tab, add a Library. You should be able to choose JUnit to your project. This is a little bit different than just having the JUnit jar file In your project. In your Run Configuration for the JUnit test, check the Classpath. You could probably fix this by adding making sure your Classpath can see that SelfDescribing class there. The Run option in Eclipse has a different set of options for the JUnit options.
If this problem arise in a RCP project it can be because JUnit has been explicitly imported. Check the editor for your plugin.xml under Dependencies tab, remove the org.junit from the Imported Packages and add org.junit to the Required Plug-ins.
The problem is when you set up eclipse to point to JRE instead of JDK. JRE has junit4.jar in the lib/ext folder, but not hamcrest.jar :) So the solution is to check installed JREs in Eclipse, remove the existing one and create a new one pointing to your JDK.
This happens when you run Ant via command line. The implicit user dependencies are added in the classpath at the end and take precedence over the project-added classpath. Run Ant with -nouserlib flag. The implicit dependencies would be excluded from the classpath.
There is a better answer to solve this problem. add dependency <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-all</artifactId> <version>1.3</version> <scope>test</scope> </dependency>
The hamcrest-core-1.3.jar available on maven repository is deprecated. Download working hamcrest-core-1.3.jar from official Junit4 github link . If you want to download from maven repository, use latest hamcrest-XX.jar. <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest</artifactId> <version>2.2</version> <scope>test</scope> </dependency>
I had the same problem, the solution is to add in build path/plugin the jar org.hamcrest.core_1xx, you can find it in eclipse/plugins.
A few steps you have to follow: Right click on the project. Choose Build Path & then from its menu choose Add Libraries. Choose JUnit then click Next. Choose JUnit4 then Finish. This works for me...
"java.lang.SecurityException: class" org.hamcrest.Matchers "'s signer information does not match signer information of other classes in the same package" Do it: Right-click on your package click on Build Path -> Configure Build Path Click on the Libraries tab Remove JUnit Apply and close Ready.
Try adding the jar files manually or try with force update with the latest hamcrest.jar