HiEveryone,
I'm a beginner in Javafx
and learning it to make app from someone tutorials, Now the problem is .. it's giving me an error as Expression expected
? What's that mean ? Can anyone pls resolve my issue?..
Have a look into this SCREENSHOT .
here is my source codes:
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.AnchorPane;
public class Main extends Application {
Stage primaryStage;
BorderPane rootLayout;
@Override
public void start(Stage primaryStage){
this.primaryStage=primaryStage;
primaryStage.setTitle("Address App");
initSample2Layout();
showSample();
}
public void initSample2Layout(){
try{
//here loading files from FXML..
FXMLLoader loader=new FXMLLoader();
loader.setLocation(Main.class.getResource("sample/Sample2.fxml"));
rootLayout=(BorderPane).loader.load();
Scene scene=new Scene(rootLayout);
primaryStage.setScene(scene);
primaryStage.show();
}catch(Exception e){e.printStackTrace();}
}
public void showSample(){
try{
//here we're loading files from FXML..
FXMLLoader loader2=new FXMLLoader();
loader2.setLocation(Main.class.getResource("sample/sample.fxml"));
AnchorPane ap=(AnchorPane).loader.load();
rootLayout.setCenter(ap);
}catch(Exception e){e.printStackTrace();}
}
public Stage getPrimaryStage(){
return primaryStage;
}
public static void main(String[] args) {
launch(args);
}
}
This is not valid syntax :
rootLayout=(BorderPane).loader.load();
If you want to cast to BorderPane
, do :
rootLayout=(BorderPane)loader.load();
And the same goes for AnchorPane ap=(AnchorPane).loader.load();
, which should be changes to AnchorPane ap=(AnchorPane)loader2.load();
.
You have rootLayout=(BorderPane).loader.load();
with an extra . character before loader
.
You probably want the following:
rootLayout=(BorderPane) loader.load();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.