Unable to call a class into javafx
已回答
I am a new Java learner. I rewrite an example for a GUI from the book I was following. A class object that belongs to a different project class is to be used in this new GUI class. Though everything was the same as in the example the GUI file couldn't create the external class object. I uploaded the file. Upload ID: 2021_12_02_ACewZt6ao8Cy4Rxo (file: OblongGUI2.java). Can you help me solving this issue?
请先登录再写评论。
I had no problem running the code with Java 13 in IDEA 2021.3 just now.
Please post the actual error message, and also share the entire project if possible.
Thanks for your answer. I uploaded the other project class. Upload ID: 2021_12_02_KrgJ5YJYgnQLuWQ3 (file: Oblong.java)
Here below the screenshots for the problem. I couldn't manage the project upload since only files are allowed. How can I share the project?
You need to place the Oblong.java file into the src/main/java/com/example/hello_worldfx folder. Then its declaration and methods will become available in the OblongGUI2.java class.
I placed Oblong file into hello_worldfx folder. It seems the problem partly solved. After the implementation the system didn't allow me to run OblongGUI2 file but Oblong file. When I run Oblong file then I had the following failure report.
I believe the IDE is picking up the configuration that was run previously, which currently has Oblong class selected as active:
See https://www.jetbrains.com/help/idea/run-debug-configuration.html for more information on run configurations.
In order to run the OblongGUI2 class, you need to click on the 'Run' green arrow button next to the class' declaration. That will automatically make it the default class to run in the current context:
I implemented the steps you adviced. GUI class worked but gave some other failures. Than I renewed the project but the same failures appeared. As I told at the begining, I am a new learner and selflearning from the books. Since I don't have an IT background, I am getting into trouble when some implementation is not in detail defined. Everything was well till I started to JavaFx for front-end development. I had structural problems and I couldn't proceed more than 1.5 months. I lost my hope to continue after such amount of failures. Anyway, thanks for your kind support.
Which ones? Maybe I can help?
You can also check out the following tutorials & articles:
I created a new project with the same files according to the link you have sent me. The same failure appeared again. It is as below.
Looks like the exception is caused by bad code:
Check line 65 of the OblongGUI3.java file.
Possible solutions can be found e.g. in these posts:
Yes, it is true. I had made a wrong writing while transferring the codes. That's very kind of you. Thanks a lot for your patience and support.
Of course, happy to help 👍