Hello Guest

WebStart Resource NullPointerException

  • 16 Replies
  • 14332 Views
WebStart Resource NullPointerException
« 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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]

ms3dloader
    -sources (main.java, timer.java, etc.)
ms3dloader.data
    -ResourceLoader.java
ms3dloader.data.models
     -g36c.ms3d
ms3dlaoder.data.textures
     -g36c.bmp


WebStart Resource NullPointerException
« Reply #1 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

WebStart Resource NullPointerException
« Reply #2 on: August 08, 2006, 08:51:22 »
The JNPL does not work :(
Only displays a text message in my browser.
Quote
Tim Biedert  Loading and rendering of Milkshape3D Models in Java Milkshape3D Models

*

Offline oNyx

  • ***
  • 177
  • 弾幕
WebStart Resource NullPointerException
« Reply #3 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.

WebStart Resource NullPointerException
« Reply #4 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.

WebStart Resource NullPointerException
« Reply #5 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...

WebStart Resource NullPointerException
« Reply #6 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 ;)

WebStart Resource NullPointerException
« Reply #7 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! :)  )

WebStart Resource NullPointerException
« Reply #8 on: August 11, 2006, 07:28:42 »
All working with 1.0 betas?

WebStart Resource NullPointerException
« Reply #9 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:
Code: [Select]
Display.setDisplayMode(new DisplayMode(640, 480));
Display.setVSyncEnabled(true);
Display.setTitle(this.windowTitle);
Display.create();


Since lesson 17 I'm using this:
Code: [Select]
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

WebStart Resource NullPointerException
« Reply #10 on: August 11, 2006, 08:08:10 »
For fixed window sizes you can use the getAvailableDisplayModes method from the util package.

IMO that should work quite good ;)

WebStart Resource NullPointerException
« Reply #11 on: August 11, 2006, 08:23:50 »
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

WebStart Resource NullPointerException
« Reply #12 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.

WebStart Resource NullPointerException
« Reply #13 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

WebStart Resource NullPointerException
« Reply #14 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? ^^