title: JavaFx cannot cast text to textField and cannot cast textField to text?
body: <p>I am trying to do an application for my Java class. Mainly we are learning out to use github, but my problem came with JavaFX. I am suppose to create a form on several panes and Scenes, and right at the last one when the user hits submit the TextFields content should be placed inside a file.</p>
  
  <p>My idea to achieve this was to pass the textfields into the last pane has a parameter and create a bufferedwriter once the submit button is pressed, adding all the text into a new file. so the idea was working perfect, I passed a Pane since all the textFields are inside one VBox and when I write them I cast them has textFields, but when I run it tells me that text cannot be cast to textfield, so when I try to cast to text instead, it would tell me the opposite! that textfield cannot be cast to text! I tried the buffer using the textArea inside the code and it worked fine! I don't understand why is not working with the pane im passing</p>
  
  <p>Note: right at the end I tried concatenating to a string see if the buffer was the problem, but it tells me the same error even doing it this way </p>
  
  <p>this is the code:</p>
  
  <pre><code>    public class RulesPane extends VBox{
      public RulesPane(Stage mainStage, Scene mainScene, Pane pane) {
          this.setAlignment(Pos.TOP_CENTER);
  
          BackgroundImage background = new BackgroundImage(new Image("water.png",900,600,false,true), 
                  BackgroundRepeat.REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.DEFAULT,
                    BackgroundSize.DEFAULT);
          this.setBackground(new Background(background));
  
          File logoPath = new File("src/swimclub_Logo.png");
          Image logoImage = new Image(logoPath.toURI().toString());
          ImageView logo = new ImageView(logoImage);
  
          TextArea agreement = new TextArea();
          agreement.setEditable(false);
          agreement.setPrefHeight(400);
          agreement.setMaxWidth(600);
          agreement.setWrapText(true);
          agreement.setText("This is text");
  
          CheckBox agree = new CheckBox("I Agree");
  
          HBox buttons = new HBox();
          buttons.setPadding(new Insets(50, 0, 0, 60));
          buttons.setSpacing(300);
  
          Button back = new Button();
          back.setText("Back");
          back.setOnMouseClicked(e-&gt;{
              mainStage.setScene(mainScene);
          });
  
          Button exit = new Button();
          exit.setText("Exit");
          exit.setOnMouseClicked(e-&gt;{
              Platform.exit();
          });
  
          Button submit = new Button();
          submit.setText("Submit Form");
          submit.setDisable(true);
          submit.setOnMouseClicked(e-&gt;{
              File file = new File("user_info.txt");
              try {
                  BufferedWriter out = new BufferedWriter(new FileWriter(file));
                  String contentToSave = "";
                  for(int i = 0; i &lt; pane.getChildren().size(); i++) 
                      contentToSave += ( (TextField) pane.getChildren().get(i)).getText();
  
                  out.write(contentToSave);
                  out.flush();
                  out.close();
              } catch (IOException e1) {
  
                  e1.printStackTrace();
              }
          });
  
  
          //CheckBox event handler to make the submit button available or unavailable when pressed
          agree.setOnAction(e-&gt;{
              if(agree.isSelected()) 
                  submit.setDisable(false);
              else
                  submit.setDisable(true);
          });
  
          buttons.getChildren().addAll(back, exit, submit);
          this.getChildren().addAll(logo , agreement, agree, buttons);
          }
  }
  </code></pre>
  
  <p>This is where is coming from </p>
  
  <pre><code> public class registration extends Application{
  
  public static void main(String[] args) {
      Application.launch(args);
  }
  
  public void start(Stage primaryStage) throws Exception {
      BorderPane main = new BorderPane();
      VBox questions = new VBox();
      VBox titlePane = new VBox();
      HBox buttonPane = new HBox();
  
  
      Text title = new Text("Welcome to the Swimming Club Registration!");
  
  
      Text question1 = new Text("How did you hear about our club?");
      Text question2 = new Text("Have you ever been in any clubs for swimming before?");
      Text question3 = new Text("Do you swim competitvly or for fun?");
  
      TextField question1Answer = new TextField();
      TextField question2Answer = new TextField();
      TextField question3Answer = new TextField();
      question1Answer.setPromptText("Enter where you heard about our club (Internet, Flyer, etc)");
      question2Answer.setPromptText("Enter Yes or No");
      question3Answer.setPromptText("Enter Competitvly or Fun");
  
      Button cancelButton = new Button("Cancel");
      Button continueButton = new Button("Continue");
  
      File logoPath = new File("src/swimclub_Logo.png");
      Image logoImage = new Image(logoPath.toURI().toString());
      ImageView logo = new ImageView(logoImage);
  
      buttonPane.getChildren().addAll(cancelButton, continueButton);
      titlePane.getChildren().addAll(title, logo);
      questions.getChildren().addAll(question1,question1Answer,question2,question2Answer,question3,question3Answer);
  
      titlePane.setAlignment(Pos.CENTER);
      buttonPane.setAlignment(Pos.CENTER);
  
      titlePane.setPadding(new Insets(10,0,20,0));
      questions.setPadding(new Insets(0,10,0,10));
      buttonPane.setPadding(new Insets(0,0,10,0));
  
      main.setTop(titlePane);
      main.setCenter(questions);
      main.setBottom(buttonPane);
  
  
  
      Scene scene = new Scene(main, 900, 600);
      primaryStage.setScene(scene);
      primaryStage.show();
  
      /**
       * @josegeorges
       * here I am adding the rules pane with the rules scene and setting up the
       * continueButton to go to it for now
       * I am also saving the textFields into a string and passing the content to the pane
       */
      continueButton.setOnMouseClicked(e-&gt;{
      String contentToSave = "";
      contentToSave += question1Answer.getText() + ",";
      contentToSave += question2Answer.getText() + ",";
      contentToSave += question3Answer.getText() + ",";
  
      RulesPane rulesPane = new RulesPane(primaryStage, scene, contentToSave);
      RulesScene rulesScene = new RulesScene(rulesPane);
          primaryStage.setScene(rulesScene);
      });
  
  }
  
   }
  </code></pre>