LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: xindon on August 07, 2006, 21:58:44

Title: WebStart Resource NullPointerException
Post by: xindon on August 07, 2006, 21:58:44
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

Title: WebStart Resource NullPointerException
Post by: xindon on August 08, 2006, 07:27:23
Duh....

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

Have a look: http://bloody-blades.de/jnlp/ms3dloader.jnlp
Title: WebStart Resource NullPointerException
Post by: Evil-Devil on August 08, 2006, 08:51:22
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
Title: WebStart Resource NullPointerException
Post by: oNyx on August 08, 2006, 08:58:21
Missing Mime-Type. This tutorial covers that bit, too:

http://www.cokeandcode.com/webstarthowto

RMB->save->doubleclick should work tho.
Title: WebStart Resource NullPointerException
Post by: Evil-Devil on August 08, 2006, 09:10:27
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.
Title: WebStart Resource NullPointerException
Post by: xindon on August 08, 2006, 11:47:50
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...
Title: WebStart Resource NullPointerException
Post by: Evil-Devil on August 08, 2006, 13:06:41
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 ;)
Title: WebStart Resource NullPointerException
Post by: xindon on August 10, 2006, 20:17:57
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! :)  )
Title: WebStart Resource NullPointerException
Post by: Evil-Devil on August 11, 2006, 07:28:42
All working with 1.0 betas?
Title: WebStart Resource NullPointerException
Post by: xindon on August 11, 2006, 07:45:47
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
Title: WebStart Resource NullPointerException
Post by: Evil-Devil on August 11, 2006, 08:08:10
For fixed window sizes you can use the getAvailableDisplayModes (http://www.lwjgl.org/javadoc/org/lwjgl/util/Display.html#getAvailableDisplayModes(int,%20int,%20int,%20int,%20int,%20int,%20int,%20int)) method from the util package.

IMO that should work quite good ;)
Title: WebStart Resource NullPointerException
Post by: xindon on August 11, 2006, 08:23:50
Quote from: "Evil-Devil"For fixed window sizes you can use the getAvailableDisplayModes (http://www.lwjgl.org/javadoc/org/lwjgl/util/Display.html#getAvailableDisplayModes(int,%20int,%20int,%20int,%20int,%20int,%20int,%20int)) 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
Title: WebStart Resource NullPointerException
Post by: Evil-Devil on August 11, 2006, 08:30:10
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.
Title: WebStart Resource NullPointerException
Post by: xindon on August 11, 2006, 08:33:13
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
Title: WebStart Resource NullPointerException
Post by: Evil-Devil on August 11, 2006, 08:35:57
Quote from: "xindon"
Brrrr, changing 10 tutorials, creating new jars, signing them... *argh* :P
What about build files like ANT? ^^
Title: WebStart Resource NullPointerException
Post by: xindon on August 11, 2006, 08:44:24
Quote from: "Evil-Devil"
Quote from: "xindon"
Brrrr, changing 10 tutorials, creating new jars, signing them... *argh* :P
What about build files like ANT? ^^

Never used such stuff, maybe I should start doing it  {grin}
Title: WebStart Resource NullPointerException
Post by: xindon on August 11, 2006, 18:38:00
Okay, weird. At home on my Linux machine everything works fine. I can even use fullscreen mode.
Maybe the problem is my quad head setup at work?

Regards