0

Problem has been solved

I have a javaFXML application. I want from my controller to use this object:

 TempClass tempObject = new TempClass();

I put the above piece of code inside this method

public class FXMLDocumentController implements Initializable

When I run it, it says that this line

 TempClass tempObject = new TempClass();

is not found.

Here what I did then but I failed in fixing it anyways:

1- I made sure that the TempClass class is in the same package (in such a way that I can see that my controller and my class are in the same file).

2- I tried to put above it @FXML trying to see if this works but it i did not.

3- I thought that I can just define this class object in the main FXML java file (the one that has the the start method) but the problem is that the IDE underlines every tempObject word in the controller.

So, all what I did is useless. How can I define it then? Update: Also, if it is applicable, is it a logical problem or a just a technical java problem?

Note1: I am really a beginner in java.

Note2: I think my problem is more to be related to how JavaFXML works than to be related to an OOP misunderstanding but anyways I included the tag: class just in case.

EDIT1: Here does not answer my question in an efficient way and here is why:

1- My question is so specific between a java class and the controller. The question in the link, however, answers a very general case, and indeed, it might answer the case where someone wants to make a communication between two windows or passing parameters to the controller (so an "A" method uses the controller) but my question is that how to let the controller uses my method). With all what I said, I do not deny the fact that this is very related to my question but it is not within the same scope.

2- My level of understanding java is so weak. I know that this is my problem but I am trying to solve the problem, not necessarily the way I want, but the way that can fit my code so that I do not change the whole code. i.e, I keep up with new ways of understanding how Java works and at the same time I try to tolerate my low level of understanding or my weak experience with Java tools and libraries.

EDIT2: The purpose of my class: My class is just a "flag" class. I am just sending notifications (flags) from my controller's buttons to my class variables. When I click on another button, I need to have these flags so that I know in what state I am.

Community
  • 1
  • 1
Gold_Sky
  • 103
  • 4
  • Possible duplicate of [Passing Parameters JavaFX FXML](http://stackoverflow.com/questions/14187963/passing-parameters-javafx-fxml) – fabian Mar 06 '16 at 20:09
  • Also http://stackoverflow.com/questions/1022880/accessing-a-variable-from-another-class – fabian Mar 06 '16 at 20:10
  • I solved the problem. Now, what should I do? Do I delete the question ? – Gold_Sky Mar 06 '16 at 20:46
  • I voted for close as duplicate which means it's currently in the review queue and will be closed if 4 high rep users agree with me, so I guess it will be closed if you give it some time. What YOU should do is consider if this question adds anything useful to this site that hasn't been posted somewhere else and / or if there's anything to gain/loose (especially reputation). That said if you delete too many questions (or get them deleted), you'll eventually be question banned (see http://stackoverflow.com/help/question-bans , not sure whether this treats self-deleted question any different). – fabian Mar 06 '16 at 21:01
  • 1
    If you think that you can bring something useful and new (considering the already existing answers) you can also answer to your own question. – C.Champagne Mar 06 '16 at 21:16

0 Answers0