2014-09-04 70 views
0

HiEveryone,作爲「預期表達」獲取錯誤?

我在Javafx一個初學者,學習它從別人的教程,現在的問題是讓應用..它給了我一個錯誤Expression expected?那是什麼意思 ?任何人都可以解決我的問題嗎?..

看看這個SCREENSHOT

這裏是我的源代碼:

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); 
    } 
} 

回答

1

這不是有效的語法:

rootLayout=(BorderPane).loader.load();

如果你想轉換爲BorderPane,做到:

rootLayout=(BorderPane)loader.load();

和山姆e爲AnchorPane ap=(AnchorPane).loader.load();,應更改爲AnchorPane ap=(AnchorPane)loader2.load();

+0

不使用代碼塊? – JonK 2014-09-04 10:53:50

+1

((BorderPane)loader).load();在預製的ref不能訪問加載 – Shail016 2014-09-04 10:54:42

+0

現在得到這個問題.. [ScreenShot](http://postimg.org/image/x6wb3itft/)。 ?? – 2014-09-04 10:55:51

0

您有rootLayout=(BorderPane).loader.load();與額外loader之前的字符。

你可能想以下幾點:

rootLayout=(BorderPane) loader.load();