WebStart Resource NullPointerException

Started by xindon, August 07, 2006, 21:58:44

Previous topic - Next topic

xindon

Okay, problem is solved.

Have a look at my WebStart Milkshape3D model loader 8)
-> http://bloody-blades.de/jnlp/ms3dloader.jnlp

(RightClick -> Save As...  and then run it using javaws)



If you're receiving NullPointerExceptions when accessing resources in a WebStart app, here's my post. The solution is written in the next post. Good look ;)


Quote
Hey,

I'm trying to start my Milkshape3D loader as a webstart application. The jars are all signed and actually everything works well.
But I can't load resources from the jar.

My resource loader looks like this:
public class ResourceLoader {

	public URL loadResource(String resource) {

		if (resource.startsWith("/"))
			resource = resource.substring(1);

		return this.getClass().getResource(resource);
	}

	public InputStream loadResourceAsStream(String resource) {

		try {
			return this.loadResource(resource).openStream();
		} catch (Exception e) {
			return null;
		}

	}
}



And in my game code, I call this for example:
MS3DModel g36c = new MS3DModel(resourceLoader.loadResourceAsStream("models/g36c.ms3d"));


The weird thing is, that in Eclipse it works, but in Webstart a NullPointerException is thrown.

Any ideas?

Thank you very much,
Tim


My package structures are as following:
ms3dloader
    -sources (main.java, timer.java, etc.)
ms3dloader.data
    -ResourceLoader.java
ms3dloader.data.models
     -g36c.ms3d
ms3dlaoder.data.textures
     -g36c.bmp


xindon

Duh....

I used ResourceLoader as a static object, that was the problem.

Have a look: http://bloody-blades.de/jnlp/ms3dloader.jnlp

Evil-Devil

The JNPL does not work :(
Only displays a text message in my browser.
QuoteTim Biedert  Loading and rendering of Milkshape3D Models in Java Milkshape3D Models

oNyx

Missing Mime-Type. This tutorial covers that bit, too:

http://www.cokeandcode.com/webstarthowto

RMB->save->doubleclick should work tho.

Evil-Devil

Quote from: "oNyx"Missing Mime-Type. This tutorial covers that bit, too:

http://www.cokeandcode.com/webstarthowto

RMB->save->doubleclick should work tho.
Yea, i forgot ;)

@Topic: Nice. Seems that we have allmost the main model formats with an example in the boards.

xindon

Thanks.
But note animation is not implemented (yet). I wrote this loader in C++ a while ago and now I just tried to convert it to Java and make a WebStart application out of it.

When I'm at home, I'll create a web page for my loader with the sources on it.

Btw, I made the G36C model myself :P


Quote from: "Evil-Devil"Seems that we have allmost the main model formats with an example in the boards.
Maybe someone should create a sticky Thread or a Wikipage with all the examples on it...

Evil-Devil

The wiki will receive an update soon...and then there can plenty content added. Just need some more time and matzon have to update it ;)

xindon

Check this out:
http://bloody-blades.de/?page_id=3

I ported the first 25 NeHe lessons to Java and made WebStart Apps!

(with working MIME type! :)  )

Evil-Devil


xindon

Yup, currently I'm using 1.0beta2.

But I just found out lesson 17 and later doesn't work on Linux.

I receive "X Error - serial:19, error_code: BadValue(integer parameter our of rance for operation), request_code:1, minor_code:0"

I'm quite sure the problem is the DisplayMode. In lesson 17 I started including Fullscreenmode.

Up to lesson 16 I used this to create the Display:
Display.setDisplayMode(new DisplayMode(640, 480));
Display.setVSyncEnabled(true);
Display.setTitle(this.windowTitle);
Display.create();


Since lesson 17 I'm using this:
DisplayMode modes[] = Display.getAvailableDisplayModes(); // Get the available display modes
DisplayMode selection = new DisplayMode(0, 0);
for (int i = 0; i < modes.length; i++) {
	if (modes[i].getWidth() == 640 && modes[i].getHeight() == 480 && (modes[i].getBitsPerPixel() == 24 || modes[i].getBitsPerPixel() == 32)) {
		selection = modes[i];
		break;
	}
}
Display.setDisplayMode(selection); // Set the display mode
Display.setVSyncEnabled(true); // Enable VSync
Display.setTitle(this.windowTitle);
Display.create();


When I'm at home I'll try to change the line DisplayMode selection = new DisplayMode(0, 0); to DisplayMode selection = new DisplayMode(640, 480);, so there's a default window mode.

I  think you cannot emumerate the resolutions in Linux. I had the same problem using Java/AWT. There's an example on the Sun / Java3D website, and it only returned the current resolution (1280x1024). In windows it returns everything supported by the graphics card.

Bug?

Regards,
xindon

Evil-Devil

For fixed window sizes you can use the getAvailableDisplayModes method from the util package.

IMO that should work quite good ;)

xindon

Quote from: "Evil-Devil"For fixed window sizes you can use the getAvailableDisplayModes method from the util package.

IMO that should work quite good ;)

What do you mean by fixed window sizes?

Is it possible that Linux doesn't support a fullscreen mode like in Windows? That you can only have fullscreen, if the window size is the same as the desktop size.

Regards

Evil-Devil

With "fixed" size I only mean your if conditional that looks for 640*480 * 24 / 32 ;)

With the function you don't need the if conditional.
@linux: don't know. As long as ATI do not give out quality display drivers, my linux experience will lack more and more.

xindon

Ah okay, but maybe in later projects I'll use your advice :)

But for now I first need to fix the Linux bug, tonight when I'm at home.


Brrrr, changing 10 tutorials, creating new jars, signing them... *argh* :P

Evil-Devil

Quote from: "xindon"
Brrrr, changing 10 tutorials, creating new jars, signing them... *argh* :P
What about build files like ANT? ^^