Could not find main class : Program will exit - eclipse

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

Related

Pyspark & Jupyter: Unsupported major.minor version 52.0

I downgraded from JDK 1.8 to 1.7 as I'm trying to deal with another problem for which one suggestion was to use 1.7.
However I'm now finding that my Juypyter notebook now hangs on this line:
spark = SparkSession.builder.appName("Basic").master("local[*]").config("spark.network.timeout","50s").config("spark.executor.heartbeatInterval", "50s").getOrCreate();
Looking at the console I see:
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/spark/launcher/Main : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
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$100(Unknown Source)
at java.net.URLClassLoader$1.run(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)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Which from searching I understand is due to different versions of Java being used. However both my path and Java_Home are pointing to 1.7 not 1.8 and I rebooted my machine. What else should I do? Should I remove and re-do my pip install of pyspark?
Just use a Docker container from: https://github.com/jupyter/docker-stacks
Why make it difficult for yourself?

i m using a POS Tagger with this code

I'm using a POS Tagger with eclipse, here is code
package tagger;
import java.io.*;
import edu.stanford.nlp.tagger.maxent.MaxentTagger;
public class ab_web
{
public static void main(String[] args)
{
MaxentTagger tagger = new MaxentTagger( " D:\\tagger\\english-bidirectional-distsim.tagger");
String sample = "i go to school by bus";
String tagged = tagger.tagString(sample);
System.out.println(tagged);
}
}
but I am having exceptions
Exception in thread "main" java.lang.UnsupportedClassVersionError: edu/stanford/nlp/tagger/maxent/MaxentTagger : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
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$100(Unknown Source)
at java.net.URLClassLoader$1.run(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)
at tagger.ab_web.main(ab_web.java:8)
kindly tell me any solution for this?
Unsupported major.minor version 52.0 means that the MaxentTagger class you are trying to use was compiled using Java 8 but you are trying to run it using an earlier version of Java.
Look in the Eclipse 'Run > Run Configurations' menu and find your program. Make sure the 'Java Runtime Environment' is set to use Java 8 (or JavaSE-1.8').
If no Java 8 is listed in the Run Configuration you may have to tell Eclipse about the location of a Java 8 JRE. Open the Eclipse Preferences and go to 'Java > Installed JREs' to do this.
You must be running Eclipse Mars or Luna to get full Java 8 support.

IBM HeapAnalyzer wont open

I downloaded IBM Support Assistance Workbench, Installed HeapAnalyzer 4.5.4. When I try and start the HeapAnalyzer tool I get this error:
Cannot Launch HeapAnalyzer - Could not find the main class: com.ibm.jinwoo.heap.HeapAnalyzer
Today 8:22 AM | Tags: heapanalyzer, installation, run
Unanswered question This question has not been answered yet.
I cannot seem to launch HeapAnalyzer
C:\Software\IBMHeapAnalyzer>java -Xmx1g -jar ha454.jar
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/ibm/jinwoo/heap/HeapAnalyzer : 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)
Could not find the main class: com.ibm.jinwoo.heap.HeapAnalyzer. Program will exit.
Has anyone else experienced this and know how to fix it?
type java --version does the version agree with 51.0
refer to stackoverflow.com/questions/10382929/…
you may need to install the latest jdk, or you can export the JAVA_HOME for the IBM JDK and add $JAVA_HOME/bin to your path

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 !