0

I get a NullPointerException for FXML loader when I execute the below in IntelliJ, but not in Eclipse IDE

Parent root = FXMLLoader.load(getClass().getResource("/view/MainView.fxml"));

Please note, the project is the same (not copy) opened in the 2 IDE's simultaneously, since it is the same project opened, the file / folder structure is the same. My search in this forum & on google for this specific issue so far has drawn blanks.

Seek guidance as to what settings I need to check / change in the IntelliJ to get it working?

iCoder
  • 1,406
  • 6
  • 16
  • 35
  • 1
    Perhaps this is a duplicate of [How to convert a normal java project in intellij into a JavaFx project](http://stackoverflow.com/questions/23421325/how-to-convert-a-normal-java-project-in-intellij-into-a-javafx-project), though the answer there might be outdated. Anyway, take a look at it and see if it helps resolve your problem. Double-check the target output of your build to see if the fxml file has actually been copied there from the source by the build process (it should have been). – jewelsea Apr 22 '16 at 06:01
  • @jewelsea addition of support for fxml, css in File -> Settings -> Complier -> ResourcePatterns does not help, still get the same error. – iCoder Apr 22 '16 at 06:57
  • I am guessing it is something to do with Gradle, but unable to figure out what to change to make it read the FXML – iCoder Apr 22 '16 at 07:08
  • I don't know much about gradle, perhaps edit question to include your grade build file and the structure of your project (file folders and files in a tree). – jewelsea Apr 22 '16 at 07:26
  • The solution mentioned in this [link](https://discuss.gradle.org/t/how-to-include-everything-inside-src-main-java-to-compile/8792/9) works in some cases, but not in my case. Can anyone familiar with Gradle let me know what I am missing here. – iCoder Apr 22 '16 at 13:02

2 Answers2

0

Managed to resolve this finally.

I re-imported the project to IntelliJ as a Gradle project & added the steps in Gradle Build file as mentioned in the link earlier.

iCoder
  • 1,406
  • 6
  • 16
  • 35
0

The same error occured to me. My project used to be a Maven project, but I tried to remove all of those components. It appears I didn't quite succeed in doing so.

I noticed that the fxml files were not properly copied into the target directory.

In .idea/compiler.xml I changed the following line:

  <profile name="Maven default annotation processors profile" enabled="true">

to now read:

  <profile name="Maven default annotation processors profile" enabled="false">

This fixed the problem and allowed the FXMLLoader to find the fxml file.

Fenix
  • 1
  • 1