0

Hey i know this is a stupid question, but i have no idia how to google it.
I have copied this code directly from a book:

Btw, my main() method is empty.

package benytterning;

public class Terning
{
    
    public int værdi;

    public Terning()
    {
            kast(); 
    }

    public void kast()
    {
            double tilfældigtTal = Math.random();
            værdi = (int) (tilfældigtTal * 6 + 1);
    }
    
    public String toString()
    {
            String svar = ""+værdi;  // værdi som streng, f.eks. "4"
            return svar;
    }
}

And my compiler says this:

Exception in thread "main" java.lang.UnsupportedClassVersionError: benytterning/BenytTerning : Unsupported major.minor version 51.0
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
	at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)

Netbeans also tell me that i need to @overide the toString() method?
And that i need to make kast() private or static or final. (btw i have no idia what static and final means)

Hope someone can help. Because i really can't see whats wrong.

Solved. I need to update my JDK . And I'm on mac, so not posible..... FU apple.

Edited by hust921: n/a

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by zeroliken
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.