fx:controller classNotFoundException plugin development Follow
Hi guys,
I am developing a plugin, whose only Action launches a JavaFX application. This one loads a fxml file, where I indicate a controller by fx:controller="fxml.GUIController". This is causing error because of the controller and says is not finding the class of the controller. It is weird because if I run directly the javafx application, it loads perfectly the fxml and its controller, but when I run the plugin that launches the application, it does not work..I attach the files with the code!::
github link https://github.com/rafads7/TaskAnnotationPlugin
error:
-----Plugin Action:
Main:
fxml (just the important):
and the project structure
Please sign in to leave a comment.
Could you please attach your project? Retyping from the screenshots cause too many errors.
Thanks
Here it is the link on github: https://github.com/rafads7/TaskAnnotationPlugin
Thank you for sharing the code!
The problem is probably caused by the default class loader in FXMLLoader. It's a static field and it's changed inside the SceneBuilder, that's why it doesn't see classes from your plugin. To fix this you need to set your plugin's class loader as a default for FXMLLoader, like the following:
FXMLLoader.setDefaultClassLoader(Thread.currentThread().getContextClassLoader())
thanks Pavel, but I don't understand where should I place this code, in the Plugin class? just before the launching of the application?
You need to set your plugin's class loader right before loading .fxml file, in your case it's MainPluginApplication.start().
I've tried it this way and it worked for me:
It's a bit better than changing the default class loader because it doesn't interfere with the SceneBuilder
Thanks man!!! it works!!! ,, but then, in the class HTMLDiagramModifier.java, I cannot access to the route indicated in order to read the files. Either it says java.io.FileNotFoundException: \html\dt.html (The system cannot found the specified route) or java.io.FileNotFoundException: \dt.html (Access denied)..
I cannot access to the files since I wrote the line you told me...I wrote it better here:: https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000665130-java-io-FileNotFoundException-Access-is-denied-and-System-cannot-find-specified-route
IF YOU CAN HELP ME PLEASE!! thaanks
Hi Rafael,
we don't advise to use JavaFX in IDEA's plugins as then you would meet all issues caused by JavaFX & Swing interop: like hanging IDEA instance, etc.
To the load problem: when you call getResource() it will get the resource in the output folder as JVM has no idea about your sources. You don't need to change file in output though, but need to recompile resources and the changes from sources would be propagated to the output.
You cannot read probably because you didn't close the writer and the file is locked.
Hope it helps,
Anna
Hi Anna,
thanks for answering! now I think is too late for me to start a new application withouth JavaFX, but next time I will take it into account!
Even that, the thing is that there is no writer opened,, it does not allow me to read even on the first time, and just after trying to write (by try-catch), indeed, I think I close it...
You try to read/write file in output directory, it is updated on make and there could be all kind of conflicts. Why do you need to do that? If your plugin would be installed in user's IDEA, do you expect that your plugin's jars would be modified? That must be prohibited due to e.g. security reasons.
Yes you are right..I was doing that because I don't know why my WebViewer object was loading the html from there,, and I don't know how to set the /src/... address, I have tried all the possible paths but none of them works, is this what I would like to know how to fix.. to enter a correct path into the WebViewer and also the PrintWriter for writing.
Why do you need to write to your source code from your app?
the Webviewer needs to load a html file that draws a tree diagram, and its nodes content depends on the data the user inputs in the javafx application. As well as the user is entering new data, the diagram view should be updated.
This won't work, sorry. E.g. obviously if you publish your plugin, html file would be inside jar and you won't be able to write there without reloading of IDEA.
I guess, you need to get nodes dynamically and not hardcoded into html, though it's already out of scope of writing IDEA's plugins.
Oh, okey I understand.. the thing was confusing me because when I was running the project from the main javafx application instead of from the plugin action, it was working and updating the html... But I understand what you mean.
Thank you very much for your help and time.
Last, if it is not too much for asking you to another advice, do you know what language would be then optimal or how I could do it in order to do what I described you and be able draw a tree diagram like this one? :: (don't take into account the blue boxes, just the tree diagram).