Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Build a JavaFX Application Graphical User Interfaces Adding Interactivity

Adding Interactivity - Errors!

So I'm not sure what's going on here, I dont get the option to switch the code to "javafx.scene.Node" and it wont run :/ any thoughts?

package sample;

import javafx.application.Application; import javafx.fxml.FXMLLoader;

import javafx.scene.Group; import javafx.scene.Group; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.Scene; import javafx.scene.layout.VBox; import javafx.scene.text.Text; import javafx.stage.Stage;

import java.awt.*;

public class Main extends Application {

@Override
public void start(Stage primaryStage) throws Exception{
    //Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
    Group root = new Group();
    Text txt = new Text("Sup?");
    Button btn = new Button();
    btn.setText("Say Sup!");
    txt.setY(50);
    VBox box = new VBox();
    box.getChildren().add(box);
    root.getChildren().add(txt);
    root.getChildren().add(btn);
    primaryStage.setTitle("Sup");
    primaryStage.setScene(new Scene(root, 300, 275));
    primaryStage.show();
}


public static void main(String[] args) {
    launch(args);
}

}

Errors: Error:(26, 12) java: cannot find symbol symbol: method setText(java.lang.String) location: variable btn of type java.awt.Button

Error:(31, 27) java: no suitable method found for add(java.awt.Button) method java.util.Collection.add(javafx.scene.Node) is not applicable (argument mismatch; java.awt.Button cannot be converted to javafx.scene.Node) method java.util.List.add(javafx.scene.Node) is not applicable (argument mismatch; java.awt.Button cannot be converted to javafx.scene.Node)

1 Answer

Doli Harahap
Doli Harahap
6,246 Points

You haven't imported the button package.