加载图像错误

时间:2013-09-27 06:21:24

标签: java image javafx-2 fxml

我有一个问题 我有2个类,1个SampleController类和1个我自己制作的普通类。 (并且当然是FXML文件)。 我想通过一个按钮在一个窗格中加载一个图像。 但我想通过其他类加载图像。 但是这些类必须互相控制,这导致了这个错误:

at blackjack.ControllerToImagesBridge.<init>(ControllerToImagesBridge.java:23)
at blackjack.SampleController.<init>(SampleController.java:27)
at blackjack.ControllerToImagesBridge.<init>(ControllerToImagesBridge.java:23)
at blackjack.SampleController.<init>(SampleController.java:27)
at blackjack.ControllerToImagesBridge.<init>(ControllerToImagesBridge.java:23)
at blackjack.SampleController.<init>(SampleController.java:27)
at blackjack.ControllerToImagesBridge.<init>(ControllerToImagesBridge.java:23)
at blackjack.SampleController.<init>(SampleController.java:27)
at blackjack.ControllerToImagesBridge.<init>(ControllerToImagesBridge.java:23)
at blackjack.SampleController.<init>(SampleController.java:27)
at blackjack.ControllerToImagesBridge.<init>(ControllerToImagesBridge.java:23)
at blackjack.SampleController.<init>(SampleController.java:27)
at blackjack.ControllerToImagesBridge.<init>(ControllerToImagesBridge.java:23)
at blackjack.SampleController.<init>(SampleController.java:27)
at blackjack.ControllerToImagesBridge.<init>(ControllerToImagesBridge.java:23)
at blackjack.SampleController.<init>(SampleController.java:27)
at blackjack.ControllerToImagesBridge.<init>(ControllerToImagesBridge.java:23)
at blackjack.SampleController.<init>(SampleController.java:27)

有谁知道我怎么能解决这个问题? 非常感谢你。

1 个答案:

答案 0 :(得分:0)

如您的错误所示:递归调用

public class SampleController implements Initializable 
{ 
    Card card = new Card();     
    Dealer deal = new Dealer();   
    Images images = new Images(card, deal); 
    SampleController sample;

或更好她实际构建它的地方

@Override public void initialize(URL url, ResourceBundle rb) { 
      this.clickStartButton(null); 
      text.setEditable(false); 
      dealerscore.setEditable(false); 
      clickable = true; 
      firstcard = false; 
      extracard = false; 
      sample = new SampleController(); 
      bridge = new ControllerToImagesBridge(images, sample); 

      Image image = new Image("images/schoppen-A.png"); 
      ImageView view = new ImageView(image); 
      image1.getChildren().add(view); 
    } 

注意

enter code here sample = new SampleController();

你真正想做的事情可能是

this.sample = this;