I’ve never seen this error before, I have also never used arrayList before, I am just making this code to find out how it works. I’m mainly trying to write a method that deletes a 2D array element if the next one is equal to it (which is the case with the last two elements) I am compiling and running on the same machine and I have just updated java so I’m running the latest version. I am using Linux Ubuntu 11.10. This is the code:
import java.util.*;
public class Test{
public static void main(String[] args){
float[][] a = {{304.0f, 2743.0f},
{304.0f, 2743.0f},
{304.0f, 2754.0f},
{304.0f, 2754.0f},
{325.0f, 2764.0f},
{346.0f, 2775.0f},
{367.0f, 2775.0f},
{367.0f, 2764.0f},
{367.0f, 2754.0f},
{356.0f, 2723.0f},
{325.0f, 2691.0f},
{304.0f, 2670.0f},
{304.0f, 2639.0f},
{356.0f, 2639.0f},
{377.0f, 2650.0f},
{377.0f, 2650.0f}};
foo(a);
for (int i = 0; i < a.length; ++i)
System.out.println(a[i]);
}
public static float[][] foo(float[][] array){
List<float[]> al = new ArrayList<float[]>(Arrays.asList(array));
for (int i = 0; i < al.size(); ++i)
if (al.get(i)[0] == al.get(i+1)[0] && al.get(i)[1] == al.get(i+1)[1])
al.remove(i);
float[][] b = new float[al.size()][2];
for (int i = 0; i < al.size(); ++i)
b[i] = al.get(i);
return b;
}
}
The error I get is:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Test : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: Test. Program will exit.
also if you can suggest an easier method to do this, I would be very grateful. Thanks very much in advance!
All this means is that your version of
javac.exeis newer than your version ofjava.exe. The class filesjavac.exeis producing can’t be read by this oldjava.exe. Often people have an extra old copy ofjava.exesomeplace crazy likeC:\WINDOWS, left there by a misguided installer. Find it and either delete it or fix yourPATHsuch that your newer copy is found first.