Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 590
  • Last Modified:

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!
0
onyourmark
Asked:
onyourmark
  • 18
  • 9
2 Solutions
 
for_yanCommented:
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
0
 
for_yanCommented:
which Java version you used to compile?
0
 
for_yanCommented:
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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
for_yanCommented:
Better open new dos winodw and set PATH yourself  you'll be guranteed that you do not have jre6 in the path, only jdk7
0
 
onyourmarkAuthor Commented:
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
0
 
for_yanCommented:
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
0
 
for_yanCommented:
You don't need to uninstall anything just edit your PATH

Post the results of -version commands above
0
 
for_yanCommented:
I'd simply open the dos window
and there just set the path:

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

when you run javac and java you probably would not need any other stuff in your PATH
If you need probably a couple of folders - it will complain and you'll add them later
0
 
onyourmarkAuthor Commented:
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)
0
 
for_yanCommented:
that is waht I expected.

and what about

javac -version
0
 
onyourmarkAuthor Commented:
C:\Users\Bill\Desktop\test>javac -version
javac 1.7.0_01
0
 
for_yanCommented:
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
0
 
onyourmarkAuthor Commented:
Hi. How can I get rid of that javac 7?
0
 
for_yanCommented:
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 :) )
0
 
onyourmarkAuthor Commented:
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
0
 
for_yanCommented:
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
0
 
onyourmarkAuthor Commented:
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
0
 
for_yanCommented:
how did you compile it before ?
0
 
for_yanCommented:
this is incorrect - does not have second quote:

PATH="C:\Program Files\Java\jdk1.7.0_01\bin
0
 
for_yanCommented:
javac JavaWekaJ48TestTrainPredCsvVer.java

.java extension is required for compilataion !
0
 
for_yanCommented:
this is how you compile:

javac JavaWekaJ48TestTrainPredCsvVer.java


this is how you execute (without any exetension)

java JavaWekaJ48TestTrainPredCsvVer
0
 
onyourmarkAuthor Commented:
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" ?
0
 
for_yanCommented:
If you remove java 7 you will not have anay javac compiler which now you use form jdk1.7.0_01\bin

No sense to remove it.

You should rather remove jre6

But I'd rather craete in the foldr where youy do compilation file
setPath.bat which will have this content PATH="C:\Program Files\Java\jdk1.7.0_01\bin"
and after you open dos winodw and reach this folder where you do compilation
juts type
setPath
and then your PATH would be changed
0
 
for_yanCommented:
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
0
 
onyourmarkAuthor Commented:
Thanks. It is all working now.
0
 
onyourmarkAuthor Commented:
Working!
0
 
for_yanCommented:
Good!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 18
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now