Solved

java error

Posted on 2012-03-17
27
540 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
Comment Utility
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
Comment Utility
which Java version you used to compile?
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
that is waht I expected.

and what about

javac -version
0
 

Author Comment

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

Expert Comment

by:for_yan
Comment Utility
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
Comment Utility
Hi. How can I get rid of that javac 7?
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
how did you compile it before ?
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
Comment Utility
javac JavaWekaJ48TestTrainPredCsvVer.java

.java extension is required for compilataion !
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
this is how you compile:

javac JavaWekaJ48TestTrainPredCsvVer.java


this is how you execute (without any exetension)

java JavaWekaJ48TestTrainPredCsvVer
0
 

Author Comment

by:onyourmark
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks. It is all working now.
0
 

Author Closing Comment

by:onyourmark
Comment Utility
Working!
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
Good!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now