About Java get path problem

BaseStyles.loadStyleResources("GUI/styles/myCoolStyle.groovy");
GuiGlobals.getInstance().getStyles().setDefaultStyle("glass");
[jME3 Main] INFO com.simsilica.lemur.style.BaseStyles - loadStyleResource(GUI/styles/myCoolStyle.groovy)
[jME3 Main] INFO com.simsilica.lemur.style.BaseStyles - Loading base resource:null
8月 15, 2023 1:51:14 下午 com.jme3.app.LegacyApplication handleError
严重: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.NullPointerException: Cannot invoke "java.net.URL.toString()" because "u" is null
	at com.simsilica.lemur.style.StyleLoader.loadStyle(StyleLoader.java:162)
	at com.simsilica.lemur.style.BaseStyles.loadStyleResources(BaseStyles.java:78)
	at GUI.UI.initialize(UI.java:52)
	at com.jme3.app.state.BaseAppState.initialize(BaseAppState.java:129)
	at com.jme3.app.state.AppStateManager.initializePending(AppStateManager.java:332)
	at com.jme3.app.state.AppStateManager.update(AppStateManager.java:362)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:258)
	at com.jme3.system.lwjgl.LwjglWindow.runLoop(LwjglWindow.java:628)
	at com.jme3.system.lwjgl.LwjglWindow.run(LwjglWindow.java:717)
	at java.base/java.lang.Thread.run(Thread.java:833)

image

I’ve been tossing it around for a while and realized it’s still not working.

Try moving the groovy style file to the “assets” or “resources” folder where all other non code assets are

2 Likes

Thank you for your help.
I moved the .groovy file into assets and now it works!

But I still don’t quite understand the file-finding mechanism

https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getResource-java.lang.String-

It’s just regular class resources.

The problem was that gradle will only deal with .java files when in “src/java”… because it’s the “java source” directory. So it will compile .java files and doesn’t do anything with resources. That’s what the resources directory is for.

Also, src/groovy would have been no good because gradle would have just tried to compile it into classes… which is not what Lemur wants. Lemur wants to run the groovy file in its own environment.

Edit: if you had looked at any of your .jar files you would have seen that the .groovy file didn’t exist in any of them. It was basically sitting there in your src/java directory not available to anything but the java compiler.

3 Likes

Thanks for the quick reply this is very helpful