1

I have tried to export my processing applet to a runnable jar file from eclipse (which I am using to code it) and it exports successfully but when opened just causes a blank (grey) screen. If I run it with command prompt I get this error:

java.lang.NullPointerException: Cannot invoke "String.contains(java.lang.CharSequence)" because "jarPath" is null

When I extracted the jar sample the folders and directories seem to be incorrect too.

before (the dependencies are in the dependencies folder)

after (the dependencies are outside of the now missing dependencies folder)

I'm sure its an issue with the file structuring on generation, more specifically the dependencies. when I run it as an application eclipse it runs perfectly fine with no exceptions.

Full message:

java.lang.NullPointerException: Cannot invoke "String.contains(java.lang.CharSequence)" because "jarPath" is null at processing.core.PApplet.dataFile(PApplet.java:7673) at processing.core.PApplet.dataPath(PApplet.java:7650) at processing.core.PApplet.createInputRaw(PApplet.java:6741) at processing.core.PApplet.createInput(PApplet.java:6659) at processing.core.PApplet.loadBytes(PApplet.java:6959) at processing.awt.ShimAWT.loadImage(ShimAWT.java:384) at processing.core.PSurfaceNone.loadImage(PSurfaceNone.java:61) at processing.core.PApplet.loadImage(PApplet.java:5311) at processing.core.PApplet.loadImage(PApplet.java:5296) at net.turke1034.shootergame.game.ShooterGame.draw(ShooterGame.java:55) at processing.core.PApplet.handleDraw(PApplet.java:2201) at processing.awt.PSurfaceAWT$10.callDraw(PSurfaceAWT.java:1422) at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:354) java.lang.NullPointerException: Cannot invoke "String.contains(java.lang.CharSequence)" because "jarPath" is null at processing.core.PApplet.dataFile(PApplet.java:7673) at processing.core.PApplet.dataPath(PApplet.java:7650) at processing.core.PApplet.createInputRaw(PApplet.java:6741) at processing.core.PApplet.createInput(PApplet.java:6659) at processing.awt.ShimAWT.loadImageIO(ShimAWT.java:454) at processing.awt.ShimAWT.loadImage(ShimAWT.java:439) at processing.core.PSurfaceNone.loadImage(PSurfaceNone.java:61) at processing.core.PApplet.loadImage(PApplet.java:5311) at processing.core.PApplet.loadImage(PApplet.java:5296) at net.turke1034.shootergame.game.ShooterGame.draw(ShooterGame.java:55) at processing.core.PApplet.handleDraw(PApplet.java:2201) at processing.awt.PSurfaceAWT$10.callDraw(PSurfaceAWT.java:1422) at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:354) 

I have tried the same thing with a test project that requires no dependencies, and it runs as expected (when run in command prompt)

2
  • Have you tried exporting your application with processing? (You can do so on cli with "...processing-3.5.4\processing-java.exe" --sketch="Path to project" --force --export --platform 'windows'"). You could then look at the folder structure it generates and what's different from yours. Maybe exchange the processing generated jar with yours and see what happens (and maybe let us know). Commented May 6, 2022 at 7:36
  • I have no knowledge of how the processing app works as I've only ever used it as a library. When I created an empty sketch with the app it was noticeably different to my files, having much more jars than mine, and has a folder called java that has a plethora of files, with mine not having a java folder all. I'm confused on what you're saying in the first bit, I tried opening the eclipse project with processing but it did not accept folders (or it) Commented May 9, 2022 at 2:26

2 Answers 2

1

had the same issue, so troubleshooted for a while until i found the following solution. i'm assuming that you are using a data file similar to the data file in Processing projects to contain your dependencies.

in Eclipse, export as a runnable jar and select the option "Extract required libraries into generated JAR". once the jar is created, put this jar into a new folder. put your data folder into this folder as well. this worked for me.

no idea why this works - just threw stuff at the wall until this stuck. one troubleshooting technique i used was making a printwriter before loading any data so i could see where the computer was searching for the dependencies. the snippet below outputs the file to the same place that Processing looks for data.

 PrintWriter pw = createWriter(dataPath("test.txt")); pw.print("over here"); pw.close(); 

i used this in combination with dataPath("") to find that it was looking for dependencies outside of the jar.

Sign up to request clarification or add additional context in comments.

Comments

0

In the past (older answer here) I had success exporting runnable .jar projects from eclipse which use Processing's libraries by using the Copy required libraries into a sub-folder next to the generated jar option in Runnable Jar File Export options:

eclipse export runnable jar export menu

eclipse runnable jar file export options

This made it easier to debug java classpath issues (-cp flag when running from command line) and native library paths(-D.java.library.path command line flag).

If you're using java packages remember to specify them in PApplet.main():

public static void main(String[] args) { PApplet.main(ShooterGame.class.getCannonicalName()); } 

The above is useful only if you can't execute the jar files due to missing libraries (class not found, missing native libraries, etc.)

Regarding loading external assets, as Shivoum B mentions, you can make use of dataPath() but also sketchPath().(See this similar answer). Without seeing the path to the loadImage() call you're making I can only make assumptions, but you might be able to get away with something like this in ShooterGame.java:

loadImage(sketchPath("data" + File.separator + "yourImageName.png"); 

(Off-topic, if I read this correctly you're trying to load images in draw() ? I'd recommend loading all assets in setup() once instead of multiple times in draw(). A special case might be with the loading large assets that take time and using P2D or P3D where the OpenGL context setup might time out (in which you can load in draw() but should use a "debouncing" boolean to ensure assets are loaded only once)

8 Comments

I am loading images with booleans that make sure they haven't already been loaded, but when I export with the dependencies in a seperate folder, but I get this error: The file "src/net/turke1034/shootergame/resources/assets/image/paused.png" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable. java.lang.NullPointerException: Cannot read field "width" because "img" is null
Oh yeah forget to mention this because I wasn't sure if its important, but the dependencies are in a folder inside the project
Interesting. I've just done a test: made an eclipse package named src.net.turke1034.shootergame.resources.assets.image, dropped paused.png into it and tried to load/show it: image(loadImage("src/net/turke1034/shootergame/resources/assets/image/paused.png"), 0, 0, 100, 100);. This worked both in eclipse and using the jar exporter via File > Export > Java > Runnable Jar option (with libs copied next to the jar). When I open the runnable .jar file as an archive (e.g. with 7-zip) I see the .png inside the archive. Do you see the png in the .jar you export ? ...
...can you also print the image path you're trying to load just before loading ? (I'm wondering if something malforms the path for some reason)
I've now just realized that the grey portion of the screen is processing loading the background and the reason the rectangles do not render is simply because the first bit of code in the loop which creates and loads the image causes the exception which doesn't allow the code that renders the rectangles to be reached... That simplies the problem a lot though
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.