nus-cs2103-AY2425S1 / forum

12 stars 0 forks source link

💡Common debugging issues when setting up javafx to individual project. #163

Closed RezwanAhmed123 closed 22 hours ago

RezwanAhmed123 commented 2 weeks ago

This is a non exhaustive list of issues I faced while setting up javafx to project:

  1. I forgot to add javafx.fxml to the javafx inside of build.gradle like below so they couldn't really recognise fxml files at first. The corrected version is:
javafx {
    version = "17.0.7"
    modules = [ 'javafx.controls', 'javafx.fxml']
}
  1. in the MainWindow.fxml file I never write the controller class path properly. The corrected version is:
<AnchorPane maxHeight="-Infinity"
            maxWidth="-Infinity"
            minHeight="-Infinity"
            minWidth="-Infinity"
            prefHeight="600.0"
            prefWidth="400.0"
            stylesheets="@../css/main.css"
            xmlns="http://javafx.com/javafx/17.0.7"
            xmlns:fx="http://javafx.com/fxml/1"
            fx:controller="mortalreminder.io.MortalReminderWindow">
  1. Make sure to only use .png files for pictures.

  2. Make sure to use the correct name/path for the image file in the MainWindow folder

  3. Never change the mainClass to the appropriate one after adding the Launcher file. Corrected version:

application {
    mainClass.set("mortalreminder.io.Launcher")
}
  1. After using scene builder, I didn't change the version of javafx being used to match the system. To fix I looked for:
xmlns="http://javafx.com/javafx/17.0.7"

inside the .fxml files and changed it to 17.0.7 (used to be like 22 or something)

damithc commented 1 week ago

@RezwanAhmed123 If any of these were caused by a gap/flaw in our JavaFX tutorial, or if you have any suggestions to improve it, let us know. The tutorial was revamped since the last semester, and has not been battle-tested until now.

RezwanAhmed123 commented 1 week ago

@damithc hi prof, i think the scenebuilder part of tutorial 4 could have been improved because I noticed when scenebuilder modifies your .fxml file, the javafx version is changed to like 22 which causes a warning to flash every time you run the app and pass in a command.

anselmlong commented 1 week ago

Agreed, I was confused on why the version kept giving me an error. Thanks for these tips! 💯

zaidansani commented 1 week ago

Make sure to only use .png files for pictures.

I do not think it's limited to .png only? I'm working fine with a .jpg file! I know .webm files don't work though. There's a list in this StackOverflow post about formats that might be useful!

RezwanAhmed123 commented 1 week ago

@zaidansani i apologise for that, I only used .webm and .webp files thus I didn’t know about .jpg files.

damithc commented 1 week ago

@damithc hi prof, i think the scenebuilder part of tutorial 4 could have been improved because I noticed when scenebuilder modifies your .fxml file, the javafx version is changed to like 22 which causes a warning to flash every time you run the app and pass in a command.

@RezwanAhmed123 I've added a note about this in https://se-education.org/guides/tutorials/javaFxPart4.html#using-scene-builder-to-tweak-the-gui Is that a good-enough solution for this issue?

damithc commented 1 week ago
1. I forgot to add javafx.fxml to the javafx inside of build.gradle like below so they couldn't really recognise fxml files at first. The corrected version is:
javafx {
    version = "17.0.7"
    modules = [ 'javafx.controls', 'javafx.fxml']
}

Is this needed? I don't think we mention this in the JavaFX tutorial, and we don't have it in AB3 either.

RezwanAhmed123 commented 4 days ago

@damithc hi prof, regarding this:

Is this needed? I don't think we mention this in the JavaFX tutorial, and we don't have it in AB3 either.

I was having issues running the app without the javafx.fxml because gradle was not recognising the .fxml files for some reason. After I added it, I was working fine.

About the new note, yeah it seems good!

yadobler commented 4 days ago

@damithc hi prof, regarding this:

Is this needed? I don't think we mention this in the JavaFX tutorial, and we don't have it in AB3 either.

I was having issues running the app without the javafx.fxml because gradle was not recognising the .fxml files for some reason. After I added it, I was working fine.

About the new note, yeah it seems good!

I believe it's because of this line

    id 'org.openjfx.javafxplugin' version '0.1.0'

If you remove this line, you do not need to specify the javafx modules used like this.

However, instead you'll need to list each module's source in the dependency block (ie the win mac linux for the base, graphics, etc...)

Not sure what's the difference but they give the same result

damithc commented 4 days ago

Not sure what's the difference but they give the same result

@yadobler Thanks for looking into this. One hypothesis (needs to be verified) is that listing the JavaFX dependencies for the three OS'es explicitly will ensure they are all added to the jar file (thus making the jar file runnable on all three) while the other approach will only include the ones needed for the current OS.