0

我有个问题。
我有 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)

有谁知道我该如何解决这个问题?非常感谢。

4

1 回答 1

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样品 = 新样品控制器();

而你真正想做的可能是

this.sample = this;
于 2013-09-27T21:10:25.627 回答