Applet Error

java.lang.UnsupportedClassVersionError: BallApplet : Unsupported major.minor version 51.0

That’s my error. I am just making a simple applet which moves a red ball across the screen.

The error is thrown in the browser. When I run in eclipse, it works fine.

Any ideas?

Here’s the source -

package applet_tut_one;

import java.applet.*;
import java.awt.*;

public class BallApplet extends Applet implements Runnable {
	
	private static final long serialVersionUID = -6439819789183377101L;
	
	int x_pos = 10; 
	int y_pos = 100; 
	int radius = 20; 
	
	public void init() {

	}

	public void start() {
		@SuppressWarnings("unused")
		Thread th = new Thread(this);
	}

	public void stop() {

	}

	public void destroy() {

	}

	public void paint(Graphics g) {
		
		g.setColor (Color.red); 
		
		g.fillOval (x_pos - radius, y_pos - radius, 2 * radius, 2 * radius); 
	}

	public void run() {
		Thread.currentThread().setPriority(Thread.MIN_PRIORITY);

		while (true) {
			
			x_pos++; 
			
			repaint();

			try {
				Thread.sleep(20);
			} catch (InterruptedException ex) {
			}

			Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
		}		
	}
}

Likely your are compiling to a Java version newer than what your Java browser plugin is running. In Eclipse try set your project settings to target compile to a lower version of java.

Ok I fixed that, but now it is giving me an incorrect name error when I load it into a webpage because it is inside of a package.

Error - java.lang.NoClassDefFoundError: BallApplet (wrong name: applet_tut_one/BallApplet)

How can I fix this?

What does your html look like? Do remember when specifying the name in html use a “.” and not a “/” so it’ll be “applet_tut_one.BallApplet”

Ah, nope I used a slash. I don’t have time to fix it now but I can later.

Thanks!