0
  1. JavaFX Hello World Program -- Try 3 -- java: cannot find symbol symbol: class GridPane location: class sample.Main 0 Paolo · Lecture 182 · 16 minutes ago Lesson 180 (First JavaFX Project) works now.

In Lesson 182, when I: comment-out the FXMLLoader and try to setAlignment(), setVgap() and setHgap() through code, I get the following error:

java: cannot find symbol

symbol: class GridPane

location: class sample.Main

package sample;
 
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
 
public class Main extends Application {
 
    @Override
   public void start(Stage primaryStage) throws Exception{
//        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
 
        GridPane root = new GridPane();
        root.setAlignment(Pos.CENTER);
        root.setVgap(10);
        root.setHgap(10);
 
        primaryStage.setTitle("Hello JavaFX!");
        primaryStage.setScene(new Scene(root, 300, 275));
        primaryStage.show();
    }
 
 
    public static void main(String[] args) {
        launch(args);
    }
}
 
----------------------------------------------
Controller.java:
 
package sample;
 
public class Controller {
}
 
----------------------------------------------
 
sample.fxml:
 
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>
 
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<GridPane fx:controller="sample.Controller"
          xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
</GridPane>
 
 

When I reactivate the FXMLLoader and try to add "Label greeting", I get the following error:

java: cannot find symbol

symbol: class Label

location: class sample.Main

SOURCE CODE:

package sample;
 
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
 
public class Main extends Application {
 
    @Override
   public void start(Stage primaryStage) throws Exception{
       Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
/*
        GridPane root = new GridPane();
        root.setAlignment(Pos.CENTER);
        root.setVgap(10);
        root.setHgap(10);
*/
        Label greeting = new Label("Welcome to JavaFX!");
        root.getChildren().add(greeting);
 
        primaryStage.setTitle("Hello JavaFX!");
        primaryStage.setScene(new Scene(root, 300, 275));
        primaryStage.show();
    }
 
 
    public static void main(String[] args) {
        launch(args);
    }
}

  • 2
    Does this answer your question? [What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?](https://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-or-cannot-resolve-symbol-error-mean) – OH GOD SPIDERS Aug 28 '20 at 08:59
  • Please read [ask], especially the part about sensible titles. – Thomas Aug 28 '20 at 09:09

0 Answers0