Getting "Class Not Found" error while trying to set up a new JUNIT class in Eclipse - eclipse

While setting up a JUNIT class for a uni project I keep getting the following error (working in Eclipse Oxygen):
Class not found UnitTest
java.lang.ClassNotFoundException: UnitTest
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:688)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Cant really figure out whats going on, already tried a few question-related answers like clean up the project and checking that the test is running from my project/bin folder.

Related

Eclipse Mars JNI Error

Hi I am working on weka api in Eclipse Mars. Everything was fine until i wrote a class for LinearRegression, just then Eclipse started giving JNI error. Now other classes runs fine but when i try to run LinearRegression class the error pops up.
The first error is Error: A JNI error has occurred, please check you installation and try again followed by JVM launcher error "A java exception has occurred". And then a list of errors
Exception in thread "main" java.lang.NoClassDefFoundError: no/uib/cipr/matrix/Matrix
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: no.uib.cipr.matrix.Matrix
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
I will appreciate if someone could help me with this problem. Thanks.

java.lang.NoClassDefFoundError when running Scala JUnit Test on Scala IDE (Eclipse Kepler)

I've recently decided to install Scala IDE 3.0.3 (which is basicly Eclipse Kepler with scala plugin). I've newest specs (specs2_2.10-23.11), scalaz (2.10-7.0.4), collection (scalaj-collection_2.10-1.5) and scala library [2.10.4]
I tried to run my tests in scala using "Scala JUnit Test" but i got this error
java.lang.NoClassDefFoundError: scalaz/concurrent/Strategy$ at
org.specs2.reporter.DefaultExecutionStrategy$$anonfun$execute$1$$anonfun$2.apply(ExecutionStrategy.scala:43)
at
org.specs2.reporter.DefaultExecutionStrategy$$anonfun$execute$1$$anonfun$2.apply(ExecutionStrategy.scala:41)
at
scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:111)
at scala.collection.immutable.List.foldLeft(List.scala:84) at
org.specs2.reporter.DefaultExecutionStrategy$$anonfun$execute$1.apply(ExecutionStrategy.scala:41)
at
org.specs2.reporter.DefaultExecutionStrategy$$anonfun$execute$1.apply(ExecutionStrategy.scala:38)
at scalaz.syntax.IdOps$class.$bar$greater(IdOps.scala:15) at
scalaz.syntax.ToIdOps$$anon$1.$bar$greater(IdOps.scala:78) at
org.specs2.reporter.JUnitReporter$class.report(JUnitReporter.scala:44)
at org.specs2.runner.JUnitRunner$$anon$4.report(JUnitRunner.scala:43)
at org.specs2.runner.JUnitRunner.run(JUnitRunner.scala:50) at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException:
scalaz.concurrent.Strategy$ at java.net.URLClassLoader$1.run(Unknown
Source) at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) at
sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) ... 17 more
What causing that? I probably missing something but I can't find what.
My tests are running just fine with gradle.
Well meaby someone will find it helpfull. I find solution: I missed scalaz-concurrent jar which apparently is not included in scalaz-core. Note that you need the same version of core and concurrent in order to work.

Could not find main class : Program will exit

I was messing with the JRE setup on Eclipse. Originally the project was set to 1.6 and when set to 1.7, my program started showing a lot of errors. So when i switched back to 1.6, all the compile time errors vanished but i have a new problem now.
This was shown on the console when i tried to run the started class containing the main function. The .class files all exist. Please advice.
java.lang.UnsupportedClassVersionError: Demo : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Exception in thread "main"
Version 51.0 means the are still class files compiled with Java 7. This files wont run with a JRE 6. You have to recompile them first (Rebuild project or clean compile using ant/maven).
Check if java versions match in your Java Build path and Java Compiler in Project properties. I think you compiled with 1.6 and is trying to run with java 1.7

Javamail demo not working

I have tried running the demo msgsend from JavaMail. I have downloaded version 1.4.5 of JavaMail and unpacked it into my JDK folder. I have added mail.jar to CLASSPATH. I have compiled msgsend.java without getting any error back. However, when I then try running java msgsend I get an "Could not find the main class: msgsend" error.
I am a total noob in Java world and have spend hours browsing through the Internet trying to find an answer but to no avail in my case.
Here is what I get in the console. What am I doing wrong?
C:\Program Files\Java\jdk1.6.0_34\javamail-1.4.5\demo>echo %CLASSPATH%
C:\Program Files\Java\jdk1.6.0_34\javamail-1.4.5\mail.jar
C:\Program Files\Java\jdk1.6.0_34\javamail-1.4.5\demo>javac -cp "%classpath%" ms
gsend.java
C:\Program Files\Java\jdk1.6.0_34\javamail-1.4.5\demo>java msgsend
Exception in thread "main" java.lang.NoClassDefFoundError: msgsend
Caused by: java.lang.ClassNotFoundException: msgsend
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: msgsend. Program will exit.
C:\Program Files\Java\jdk1.6.0_34\javamail-1.4.5\demo>java -cp "%classpath%" msg
send
Exception in thread "main" java.lang.NoClassDefFoundError: msgsend
Caused by: java.lang.ClassNotFoundException: msgsend
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: msgsend. Program will exit.
C:\Program Files\Java\jdk1.6.0_34\javamail-1.4.5\demo>
Classes are case sensitive. Be sure you have the compiled MsgSend in your class path, and invoke the compiled class with the proper case.
Try java MsgSend
Edited:
This is how it will work:
Compile as you were doing:
javac.exe -cp ..\mail.jar msgsend.java
And then to run the compiled class do:
java -cp ..\mail.jar;. msgsend
In other words: you were missing the current folder in your classpath.
You didn't include the directory where msgsend.class exists, usually the current directory ("."). See the examples in README.txt included with JavaMail.

java.lang.NoClassDefFoundError while running JUnit

Hi i am getting this error please help me out, thanks
java.lang.NoClassDefFoundError: com/ge/energy/wp/core/exception/WPException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class`enter code here`.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at org.junit.internal.requests.ClassRequest.hasSuiteMethod(ClassRequest.java:62)
at org.junit.internal.requests.ClassRequest.getRunnerClass(ClassRequest.java:50)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:28)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:28)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:24)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:40)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:30)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:445)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.ClassNotFoundException: com.ge.energy.wp.core.exception.WPException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 15 more
try adding source folder to your classpath. If you use eclipse, right click test file and select Run configuration under Junit test and select classpath and add your source folders to class path.
Check class WPException. Usually your IDE should show you if something is wrong with the java file but not with the class file - either it wasn't compiled or missing (the error is triggered when the JVM can't find the class) for some other reason, one of them could be, like bluelabel mentioned, a problem with the PATH.
I know this is old post...but may help someone else...
whenever I have faced this issue only problem have been the java version eclipse is defaulted to - which is the eclipse jre.
Fix - change to the proper jre installed on your machine !