Problem with running an applet

Started by Dramentiaras, December 11, 2013, 16:50:25

Previous topic - Next topic

Dramentiaras

Hi! I'm making a test game with lwjgl 2.9.1. The game should be able to run as an applet and it does, at least in Eclipse's Applet Viewer.
When I run an applet with the <applet> html tag, the applet fails to initialize. This is the stacktrace I get:

java.lang.ExceptionInInitializerError
	at org.lwjgl.Sys.createImplementation(Sys.java:124)
	at org.lwjgl.Sys.<clinit>(Sys.java:111)
	at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
	at al.test.TestApplet.init(TestApplet.java:30)
	at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied ("java.util.PropertyPermission" "org.lwjgl.util.Debug" "read")
	at java.security.AccessControlContext.checkPermission(Unknown Source)
	at java.security.AccessController.checkPermission(Unknown Source)
	at java.lang.SecurityManager.checkPermission(Unknown Source)
	at sun.plugin2.applet.AWTAppletSecurityManager.checkPermission(Unknown Source)
	at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
	at java.lang.System.getProperty(Unknown Source)
	at java.lang.Boolean.getBoolean(Unknown Source)
	at org.lwjgl.LWJGLUtil$4.run(LWJGLUtil.java:454)
	at org.lwjgl.LWJGLUtil$4.run(LWJGLUtil.java:452)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.lwjgl.LWJGLUtil.getPrivilegedBoolean(LWJGLUtil.java:452)
	at org.lwjgl.LWJGLUtil.<clinit>(LWJGLUtil.java:265)
	... 7 more


As you can see, I get an ExceptionInInitializerError. From what I've read, that means that it failed to initialize a variable in the static scope.
The stacktrace points to this line:

Code: java
Display.setParent(parent);


In the following code:

Code: java
package al.test;

import java.applet.Applet;
import java.awt.Canvas;

import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;

public class TestApplet extends Applet {

	private Canvas parent;
	
	@Override
	public void init() {
		
		setSize(800, 600);
		
		parent = new Canvas();
		parent.setSize(getWidth(), getHeight());
		add(parent);
		parent.setFocusable(true);
		parent.requestFocus();
		parent.setIgnoreRepaint(true);
		setVisible(true);
		
		try {
			
			Display.setParent(parent);
			
			Display.create();
			Keyboard.create();
			Mouse.create();
			
		} catch (LWJGLException e) {
			e.printStackTrace();
		}
		
		Game game = new Game();
	}
	
	@Override
	public void destroy() {
		
		super.destroy();
	}
}


As I've understood it, the error exists in the Display class itself and I do not know how to fix this.

This my html file to run the applet:

Code: html
<!doctype html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
	<head>
	</head>
	<body>
		<applet code="al.test.TestApplet" archive="finished.jar" width="800" height="600"/>
	</body>
</html>


Thanks in advance!

kappa

Got of copy of what your html looks like?

Also looks like you might be using the unsigned LWJGL jars, download the LWJGL applet bundle which contains pre-signed LWJGL jars. (or alternatively sign them yourself with your own certificate),

Dramentiaras

I've updated the original thread with the html code.

I'm using JarSplice to create a single jar out of all the required jars, and therefor, the library jars shouldn't matter, right?
Does this mean I have to sign my own jar? If yes, how do I do it? I've never quite understood how to do it.

kappa

JarSplice can't be used for applets, its only for applications.

You'll have to use LWJGL's AppletLoader (recommended), see LWJGL wiki for a full in depth tutorial and LWJGL's Applet download bundle (for a working example) or look into using Java's JNLP Applets with natives.