0

I build this app and tried to move to mobile/native desktop. In mobile and native I have error loading resources from classpath. Error in desktop version:

Caused by: java.lang.NullPointerException
    at org.fxapps.alphabet.AlphabetFX.bulkDetailsImages(AlphabetFX.java:178)

It refers to this line: https://github.com/jesuino/alphabetfx/blob/master/alphabetfx/src/main/java/org/fxapps/alphabet/AlphabetFX.java#L178

However, notice I can't also load a single file, it returns null.

Check my projects: https://github.com/jesuino/alphabetfx

I noticed the same error with android app using adb.

Different approaches were tried:

  • Used latest version for gluon
  • Put everything in the same project

Notice also that it works locally, with Java only. I can't even load the file on root classpath (/details).

I have the same kind of apply of app that works greatly: https://github.com/jesuino/battleship-game

Could this be caused because I have too much assets in my classpath? Or is there some sort of cache? I can see in debug logs that it handles most of my assets.

You can reproduce the error by:

  • Build the project using mvn clean install
  • Then go into alphabetfx-app and run mvn client:build client:package
  • Try to run the executable: ./target/client/x86_64-linux/AlphabetFXApp

Please help!

EDIT:

As pointed by Jose in Twitter[1], listing resources from the JAR or native bits (without a FS) won't work, hence I am using a file called "details.txt". However I still get a null when trying to read it. I will continue with this approach and update this with my solution when I find it.

[1] https://twitter.com/JPeredaDnr/status/1323348851345002502

  • I modified the code to use a file that list all the existing images (details) but still details is null – William Siqueira Nov 02 '20 at 19:55
  • your link https://github.com/jesuino/alphabetfx/blob/master/alphabetfx/src/main/java/org/fxapps/alphabet/AlphabetFX.java#L178 is dead... – Sam YC Nov 03 '20 at 06:57

1 Answers1

0

I found the solution!

It was graalvm not copying my file to the native image. See this:

https://github.com/oracle/graal/blob/master/substratevm/Resources.md

The default configuration does not include all files in classpath into the native image. What I had to do was to rename my file to have a supported extension, I used ".dat" since ".txt" is not supported. See the list of supported resource extension by default:

File: ${App}/target/client/x86_64-linux/gvm/resourceconfig-x86_64-linux.json

{
  "resources": [
    {"pattern": ".*\\.png$"},
    {"pattern": ".*\\.jpg$"},
    {"pattern": ".*\\.jpeg$"},
    {"pattern": ".*\\.gif$"},
    {"pattern": ".*\\.bmp$"},
    {"pattern": ".*\\.ttf$"},
    {"pattern": ".*\\.raw$"},
    {"pattern": ".*\\.xml$"},
    {"pattern": ".*\\.fxml$"},
    {"pattern": ".*\\.css$"},
    {"pattern": ".*\\.gls$"},
    {"pattern": ".*\\.json$"},
    {"pattern": ".*\\.dat$"},
    {"pattern": ".*\\.license$"},
    {"pattern": ".*\\.frag$"},
    {"pattern": ".*\\.vert$"},
    {"pattern": ".*\\.obj$"}
  ]
}

  • Resources aren't included by default because static code analysis needs a config which ones to include, because the names can only be available at runtime. The config is a json file, like you show, and you can definitely create/edit it to match .txt files as well. https://github.com/oracle/graal/blob/master/substratevm/Resources.md even uses txt as the example – Oleg Šelajev Nov 11 '20 at 10:45