-2

I have created a JavaFX Java program that displays few screens. on one machine it works when I run from eclipse but fails when I run it as a jar. on another machine it fails in eclipse with the same error I get previously.

I have linked a screenshot containing part of the code and also the error and folder layout.

any assistance is appreciated.

screenshot containing part of the code and also the error and folder layout

Murigrim
  • 9
  • 1
  • 5
    1. Please don't post pictures of code, post code instead using markdown, so it is easily readable by others :) 2. You tagged javafx-8 and javafx-11, which are very different, because there was a major change in how to include JavaFX into your project, I'd suggest the easiest way is to get a JDK that includes JavaFX, (Have a look at [A JavaFX App on ZuluFX in 60 seconds](https://foojay.io/today/a-javafx-app-on-zulufx-in-60-seconds/)) – gkhaos Nov 18 '21 at 15:23
  • 2
    Edit your question and include your code, and the full stack trace of the error, as text—not as an image. See https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question. – VGR Nov 18 '21 at 15:26
  • "please don't post pictures of code, post code instead using markdown, so it is easily readable by others" - relatively new to asking questions on stack overflow. I will take this advice on board thank you. " I'd suggest the easiest way is to get a JDK that includes JavaFX" - I have used javaFX for a few years now and normally wrote with Java 1.8 but I recently received an error stating. JavaFX module was missing so I had to download the JavaFX JDK and also create a lib for it and include an argument in the build configurations. – Murigrim Nov 18 '21 at 15:32
  • _relatively new to asking questions on stack overflow_ good time to read through the help pages about how to ask (or answer) – kleopatra Nov 18 '21 at 16:37
  • The issue is now resolved, so short of going back and reimplementing the error just to get code snips, I cannot add the original code. I wont be doing that but I will take this criticism on board and ensure that I paste the code in future and not an image. – Murigrim Nov 18 '21 at 17:02
  • 1
    *"I will take this advice on board."* So why is there still a screenshot in the question? – James_D Nov 18 '21 at 21:27

1 Answers1

1

It looks like the fxml file you are trying to use is called MainForm.fxml. But on line 14 your are trying to use Mainform.fxml. Try capitalizing the 'F' on form.

JonR85
  • 700
  • 4
  • 12
  • Thank you! that fixed it. incidentally you just assisted a team of 3 coders. all three of us missed that spelling mistake, we feel like idiots!. I wonder why it was working on a different computer in eclipse, very strange. – Murigrim Nov 18 '21 at 15:34
  • @Murigrim What OS are the different computers running? Some file systems ignore case while others require the correct case. – greg-449 Nov 18 '21 at 16:24
  • It was running on my computer running eclipse and windows 10. It was failing on a machine running linux and eclipse. so you are probably correct. the interesting thing is when I exported it as a jar file on the windows machine, the Jar file would not run in CMD and was throwing me the null pointer exception error. I have never encountered a JavaFX program actually running with a spelling mistake like this. I think it threw us off. – Murigrim Nov 18 '21 at 16:53
  • 1
    “works when I run from eclipse but fails when I run it as a jar” -> jar protocol is always case sensitive, file protocol used in finding resources in an unpacked app (r.g. In eclipse) will be case insensitive on windows. Just code as though it will always be case sensitive, and it will work no matter the os or whether it is packed in a jar or not. – jewelsea Nov 18 '21 at 16:59
  • I did not know that eclipse is case insensitive on windows when finding resources. It seems very strange for it to have that functionality but its definitely something I will watching out for in the future. Thank you. – Murigrim Nov 18 '21 at 17:06
  • @Murigrim It is not Eclipse that is case insensitive, it is the Windows file system - so it applies to all programs. Linux & Unix file systems are traditionally case sensitive. macOS can be configured to have both case sensitive and insensitive file systems! – greg-449 Nov 18 '21 at 18:29
  • Print out the resource returned from [getResource()](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Class.html#getResource(java.lang.String)) using System.out.println. Do it before you pack a jar, then after. You will see that the URLs are completely different, they use different protocols. When in a jar file, the [jar: protocol is used](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/net/JarURLConnection.html). – jewelsea Nov 18 '21 at 19:21
  • but outside of a jar file, the [`file:` protocol is used](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/io/File.html#%3Cinit%3E(java.net.URI)): "The exact form of a file: URI is system-dependent". This has nothing to do with Eclipse, it is based on the change in protocol that you are using to access resources and the fact that some protocols are system-dependent. – jewelsea Nov 18 '21 at 19:23