Solved

java error

Posted on 2012-03-17
27
555 Views
Last Modified: 2012-06-22
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
Comment
Question by:onyourmark
  • 18
  • 9
27 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 37733797
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
 
LVL 47

Expert Comment

by:for_yan
ID: 37733800
which Java version you used to compile?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37733805
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 47

Expert Comment

by:for_yan
ID: 37733810
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
 

Author Comment

by:onyourmark
ID: 37733818
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
 
LVL 47

Expert Comment

by:for_yan
ID: 37733820
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
 
LVL 47

Expert Comment

by:for_yan
ID: 37733823
You don't need to uninstall anything just edit your PATH

Post the results of -version commands above
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 500 total points
ID: 37733828
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
 

Author Comment

by:onyourmark
ID: 37733831
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
 
LVL 47

Expert Comment

by:for_yan
ID: 37733834
that is waht I expected.

and what about

javac -version
0
 

Author Comment

by:onyourmark
ID: 37733839
C:\Users\Bill\Desktop\test>javac -version
javac 1.7.0_01
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37733842
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
 

Author Comment

by:onyourmark
ID: 37733844
Hi. How can I get rid of that javac 7?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37733848
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
 

Author Comment

by:onyourmark
ID: 37733881
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
 
LVL 47

Expert Comment

by:for_yan
ID: 37733897
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
 

Author Comment

by:onyourmark
ID: 37733903
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
 
LVL 47

Expert Comment

by:for_yan
ID: 37733906
how did you compile it before ?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37733907
this is incorrect - does not have second quote:

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

Expert Comment

by:for_yan
ID: 37733910
javac JavaWekaJ48TestTrainPredCsvVer.java

.java extension is required for compilataion !
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37733913
this is how you compile:

javac JavaWekaJ48TestTrainPredCsvVer.java


this is how you execute (without any exetension)

java JavaWekaJ48TestTrainPredCsvVer
0
 

Author Comment

by:onyourmark
ID: 37733985
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
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 37733989
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
 
LVL 47

Expert Comment

by:for_yan
ID: 37733994
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
 

Author Comment

by:onyourmark
ID: 37734002
Thanks. It is all working now.
0
 

Author Closing Comment

by:onyourmark
ID: 37734004
Working!
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37734005
Good!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
maven module vs maven project 3 73
Java Restore security prompts not working 10 123
how to debug htl and js pages 8 53
hashmap order 17 40
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

761 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question