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
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
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
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.
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
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" ?
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