"baseDir can not be null" using a SimpleResourceLocator in an Applet

This is post is very similar to: http://www.jmonkeyengine.com/jmeforum/index.php?topic=5885.0 but I decided to make a new one based on the topic's age.

When using a SimpleResourceLocator in an applet I get the following Exception:

java.lang.NullPointerException: baseDir can not be null.

at com.jme.util.resource.SimpleResourceLocator.<init>(SimpleResourceLocator.java:61)

The code that generates this is as follows:

SimpleResourceLocator locator = new SimpleResourceLocator( Thread.currentThread().getContextClassLoader().getResource("com/xspace/data/") );
ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, locator);

This works when debugging with the AppletViewer, but is consistently fails after deployed in an Applet.

Any ideas?

did you try with: YourClass.class.getClassLoader().getResource() ?

Yeah, I tried that too.  It didn't work but it pointed me in the right direction.  If i had take a moment to look at it i would have seen what was happening.  The URL was null indicating the resource might not be there.  So I check the path and it was fine.  I had a third party lib nearby loading a file so I looked into it to see if it was having the same problem but it was using a different a proprietary ResourceLocator.  So I tried that and it fixed the problem.

So, if anyone sees this error is means that it could not find the requested Resource and getResource is returning null.

Thanks again for you help Core-Dump.

Well now i have the same problem :slight_smile:

What was that 'different a proprietary ResourceLocator' which fixed the problem?

i'm not sure what my initial problem was, because i can't reproduce it anymore :slight_smile:

But one problem was that the al_title property contained a space:

<param name="al_title" value="Test Applet">

The other problem was, that the applications jar was not signed.

Now it works using:

  new SimpleResourceLocator(Util.class.getResource("/com/somepackage/resources/textures/")));

Leading and trailing slash are needed it seems.