Avatar of onyourmark
onyourmark
 asked on

java error

I was able to compile some java code but I get the error message. Any help would be appreciated.

C:\Users\Bill\Desktop\test>java JavaWekaJ48TestTrainPredCsvVer
Exception in thread "main" java.lang.UnsupportedClassVersionError: JavaWekaJ48TestTrain
svVer : 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: JavaWekaJ48TestTrainPredCsvVer.  Program will exit.


I was able to run a similar program called  JavaWekaJ48TestTrainPred which I then edited just a bit called JavaWekaJ48TestTrainPredCsvVer.

The edits were
1. Added in
import weka.core.converters.ConverterUtils.DataSource;

2. changed the commented part below to the uncommented:
     /*   BufferedReader readerTrain = new BufferedReader(
         new FileReader("C:/Program Files/Weka-3-7/data/weather.nominal.arff"));
        Instances dataTrain = new Instances(readerTrain);
        readerTrain.close();
            */
            DataSource sourceTrain = new DataSource("C:/Program Files/Weka-3-7/data/weather.nominal.csv");
 Instances dataTrain = sourceTrain.getDataSet();

3. changed the commented part below to the uncommented:
        /*BufferedReader readerTest = new BufferedReader(
         new FileReader("C:/Program Files/Weka-3-7/data/weather.nominalTest.arff"));
        Instances dataTest = new Instances(readerTest);
        readerTest.close();
            */
                  DataSource sourceTest = new DataSource("C:/Program Files/Weka-3-7/data/weather.nominal.csv");
 Instances dataTest = sourceTest.getDataSet();      

I am attaching the code.
My path variable looks like:
C:\Python27\;C:\Python27\Scripts;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files\ActiveState Perl Dev Kit 9.0.1\bin\;%GTK_BASEPATH%\bin;C:\Perl\site\bin;C:\Perl\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin;C:\Program Files\MySQL\MySQL Server 5.1\bin;C:\PROGRA~1\ADDINS~1\XLSTAT~1;C:\perl2exe;C:\Program Files\ActiveState Perl Dev Kit 9.0.1\bin;C:\Program Files\Windows Live\Shared;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Java\jdk1.7.0_01\bin;C:\Program Files\Android\android-sdk\tools\;C:\Program Files\Calibre2\

my classpath looks like:
.;C:\Program Files\Weka-3-7\weka.jar;C:\Program Files\Java\jre6\lib\ext\QTJava.zip

Thanks!
Java

Avatar of undefined
Last Comment
for_yan

8/22/2022 - Mon
for_yan

You are trying to execute your application with jave of lower version than you compiled it - say you compiled with Java 7 ansd want to execute with java 6
for_yan

which Java version you used to compile?
for_yan

I see that you have jdk7/bin in your path.
This was used to compile.
Im guessing that in the path before jdk7/bin you have jre6/bin - so it will pick up that java.exe from java 6 and try to execuite code compiled with jdk7 using jre from java6
Your help has saved me hundreds of hours of internet surfing.
fblack61
for_yan

Better open new dos winodw and set PATH yourself  you'll be guranteed that you do not have jre6 in the path, only jdk7
onyourmark

ASKER
Hello. How about if I uninstall java 7. I am attaching a screen shot of my installed programs. Can I unistall java 7 from here?
installed-programs.PNG
for_yan

One simple way to check is go to your dos prompt:

C:\Users\Bill\Desktop\test>

and type


java -version

and

javac -version

and post the results
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
for_yan

You don't need to uninstall anything just edit your PATH

Post the results of -version commands above
SOLUTION
for_yan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
onyourmark

ASKER
C:\Users\Bill\Desktop\test>java -version
java version "1.6.0_30"
Java(TM) SE Runtime Environment (build 1.6.0_30-b12)
Java HotSpot(TM) Client VM (build 20.5-b03, mixed mode, sharing)
for_yan

that is waht I expected.

and what about

javac -version
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
onyourmark

ASKER
C:\Users\Bill\Desktop\test>javac -version
javac 1.7.0_01
for_yan

You have this to long PATH and somewhere in the folder which has not obvious name you have jre of Java 6 - that' waht we see in java -version
As this is JRE so in the same folder there is no javac.exe (only java.exe)
so when you execute javac it goes further in the PATH and copiles it with jdk7/bin with java7
that is the cause of
Unsupported major.minor version 51.0
onyourmark

ASKER
Hi. How can I get rid of that javac 7?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
for_yan

exactly!

so ust open new DOS winodw and spcify short path as I mentioned:


PATH="C:\Program Files\Java\jdk1.7.0_01\bin"

and then both compile and execute in this winodow
and you'll not get this kind of error (you'll probably get some other errors :) )
onyourmark

ASKER
you are right :-(
C:\Users\Bill\Desktop\test>javac JavaWekaJ48TestTrainPredCsvVer
error: Class names, 'JavaWekaJ48TestTrainPredCsvVer', are only accepted if annotation proces
sing is explicitly requested
1 error
for_yan

explain what you did in detail.
before you had runtime error
now ou quote compilation error
if you compiled bfore with java 7 it shoudl compuile with java7 now also.

be specific what you did
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
onyourmark

ASKER
Here is what I did this time:
C:\Users\Bill>PATH="C:\Program Files\Java\jdk1.7.0_01\bin

C:\Users\Bill>cd C:\Users\Bill\Desktop\test

C:\Users\Bill\Desktop\test>javac JavaWekaJ48TestTrainPredCsvVer
error: Class names, 'JavaWekaJ48TestTrainPredCsvVer', are only accepted if annotation proces
sing is explicitly requested
1 error
for_yan

how did you compile it before ?
for_yan

this is incorrect - does not have second quote:

PATH="C:\Program Files\Java\jdk1.7.0_01\bin
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
for_yan

javac JavaWekaJ48TestTrainPredCsvVer.java

.java extension is required for compilataion !
for_yan

this is how you compile:

javac JavaWekaJ48TestTrainPredCsvVer.java


this is how you execute (without any exetension)

java JavaWekaJ48TestTrainPredCsvVer
onyourmark

ASKER
Hi. Thank you. It is working now! Can I ask if there is a way to remove java 7 so that I don't need to do this:
C:\Users\Bill>PATH="C:\Program Files\Java\jdk1.7.0_01\bin" ?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
for_yan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
for_yan

You actually need to set path - to remove the /bin folder of JRE6 from the path, so that when you run java command, it should get it ifrom jdk7/bin not from jre6/bin
So you are very much using JDK7 - you don't want to remve it
onyourmark

ASKER
Thanks. It is all working now.
onyourmark

ASKER
Working!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
for_yan

Good!