AssetNotFoundException: Cannot load from assets directory

I’m trying to load an asset like this:

val west = assetManager.loadTexture("Textures/sky.png")

The project structure looks like this:

assets
\Textures
\ \ sky.png

I am getting the error

com.jme3.asset.AssetNotFoundException: Textures/sky.png (Flipped) (Mipmapped)

What am I doing wrong?

I can also share my build.gradle if needed. Thanks.

Where do you place that asset folder? It should be on the class-path.

It’s in the root of the project

For Gradle applications, you should place the assets folder inside the ./src/main/resources directory.

2 Likes

Awesome. I had no idea.

I searched for this but wasn’t able to find anything outside of a few tutorials. None of which mentions main/resources. Is there any place I should have been looking instead?

There are a couple of examples around, for example:

But, you could also, search the Gradle documentation.

But, you could also, search the Gradle documentation.

Where do I find the gradle documentation?

A lot of the tutorials are still geared towards the old ANT builds which would automatically add the assets folder to the classpath. Somehow, no one has been able to get this working properly with the default gradle build in the SDK.

…so that leaves the users caught in a little bit of a lurch.

I don’t even remember if the project initializer is setting this up correctly yet.

Either way, putting resources in src/main/resources works and has been a pretty standard Java build location for resources since maven was invented… so it will work with JME too. The magic-info is that JME loads assets from the classpath by default.

The initialiser also uses the resouces folder not the assets folder. It could use the assets folder but there is a lot of discussion as to if it should. I’m on team resources folder because it’s standard gradle layout

1 Like