Мой графический интерфейс не будет отображаться даже во время работы программы. T - PullRequest
0 голосов
/ 27 апреля 2018

[введите описание изображения здесь] [1] Вот драйвер, программа будет работать без ошибок, но графический интерфейс вообще не будет отображаться. Я новичок в FX, и я просто пытаюсь заставить его работать.

public class Vacation extends Application {
private Stage stage;

 @Override
public void start(Stage stage) throws Exception {
  this.stage = stage;
  try{
    FXMLLoader loader = new 
FXMLLoader(getClass().getResource("Vacation.fxml"));
    AnchorPane pane = loader.load();

    MainControler mainController = loader.getController();
    Scene scene = new Scene(pane, 640, 450);
    stage.setScene(scene);
    stage.show();

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

    }
}

Вот FXML.

<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.141" fx:controller="Application.MainControler">
<children>
  <AnchorPane layoutX="9.0" layoutY="8.0" prefHeight="131.0" prefWidth="572.0" style="-fx-background-color: #333333;">
     <children>
        <ImageView fitHeight="106.0" fitWidth="470.0" layoutX="51.0" layoutY="13.0">
           <image>
              <Image url="@../../../../../Desktop/FxPics/dc3.jpg" />
           </image>
        </ImageView>
        <Button fx:id="DC" layoutX="229.0" layoutY="53.0" mnemonicParsing="false" onAction="#DCbuttonPpess" text="Devils CourtHouse" textFill="#ee0707" />
     </children>
  </AnchorPane>
  <AnchorPane layoutX="9.0" layoutY="149.0" prefHeight="131.0" prefWidth="572.0" style="-fx-background-color: #333333;">
     <children>
        <ImageView fitHeight="100.0" fitWidth="476.0" layoutX="49.0" layoutY="17.0">
           <image>
              <Image url="@../../../../../Desktop/FxPics/reef.jpg" />
           </image>
        </ImageView>
        <Button fx:id="STB" layoutX="226.0" layoutY="55.0" mnemonicParsing="false" onAction="#STBbuttonPress" text="Scuba The Bahamas" textFill="#01d3f8" />
     </children>
  </AnchorPane>
  <AnchorPane layoutX="9.0" layoutY="295.0" prefHeight="131.0" prefWidth="572.0" style="-fx-background-color: #333333;">
     <children>
        <ImageView fitHeight="100.0" fitWidth="488.0" layoutX="42.0" layoutY="16.0">
           <image>
              <Image url="@../../../../../Desktop/FxPics/SD2.jpg" />
           </image>
        </ImageView>
        <Button fx:id="SDC" layoutX="230.0" layoutY="53.0" mnemonicParsing="false" onAction="#SDCButtonPress" text="Sky Dive Colorado" textFill="#ffa616" />
     </children>
  </AnchorPane>
  <AnchorPane layoutX="9.0" layoutY="445.0" prefHeight="131.0" prefWidth="572.0" style="-fx-background-color: #333333;">
     <children>
        <ImageView fitHeight="106.0" fitWidth="488.0" layoutX="42.0" layoutY="13.0">
           <image>
              <Image url="@../../../../../Desktop/FxPics/c3.jpg" />
           </image>
        </ImageView>
        <Button fx:id="BC" layoutX="248.0" layoutY="54.0" mnemonicParsing="false" onAction="#BCButtonpress" text="Baron Cliffs" textFill="#543801" />
     </children>
  </AnchorPane>

а вот и контроллер.

public class MainControler implements Initializable {

     @FXML
   private Button DC;

    @FXML
    private Button STB;

    @FXML
    private Button SDC;

    @FXML
    private Button BC;


   @FXML public void BCButtonpress(ActionEvent event) {
try{
    FXMLLoader bcLoader = new 
FXMLLoader(getClass().getResource("BaronCliff.fxml"));
    Parent root1 = (Parent) bcLoader.load();
    Stage bc = new Stage();
    bc.setTitle("Baron Cliff");
    bc.setScene(new Scene(root1));
    bc.show();

}catch (IOException e){
    System.out.println("Cant Load new Window.");
}
}


  @FXML  public void DCbuttonpress(ActionEvent event) {
try{
    FXMLLoader bcLoader = new 
FXMLLoader(getClass().getResource("DevilsCourthouse.fxml"));
    Parent root1 = (Parent) bcLoader.load();
    Stage bc = new Stage();
    bc.setTitle("Devils Courthouse");
    bc.setScene(new Scene(root1));
    bc.show();

}catch (IOException e){
    System.out.println("Cant Load new Window.");
}
}


  @FXML  public void STBbuttonPress(ActionEvent event) {
 try{
    FXMLLoader bcLoader = new 
    FXMLLoader(getClass().getResource("Scuba.fxml"));
    Parent root1 = (Parent) bcLoader.load();
    Stage bc = new Stage();
    bc.setTitle("Scuba the Bahamas");
    bc.setScene(new Scene(root1));
    bc.show();

}catch (Exception e){
    System.out.println("Cant Load new Window.");
}
}


    @FXML public void SDC(ActionEvent event) {
 try{
   FXMLLoader bcLoader = new 
 FXMLLoader(getClass().getResource("Skydive.fxml"));
   Parent root1 = (Parent) bcLoader.load();
   Stage bc = new Stage();
   bc.setTitle("Skydive Colorado");
   bc.setScene(new Scene(root1));
   bc.show();

  }catch (Exception e){
   System.out.println("Cant Load new Window.");
   }
    }

Заранее спасибо за любую помощь, я, наконец, сломался и решил опубликовать это, я не мог найти никого с моей проблемой, возможно, что-то незначительное, но у меня нет никого с свежими глазами, чтобы действительно взглянуть на это. Извинения.

После помещения в e.printStackTrace (); в блоке catch я получил список исключений.

  javafx.fxml.LoadException: Error resolving 
                   onAction='#DCbuttonPpess', either the event handler is 
                not in the Namespace or there is an error in the script.

       file:/C:/Users/Kalamar/Documents/NetBeansProjects/Vacation/di 
           st/run201542084/Vacation.jar!/Application/Vacation.fxml:17

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2597)
at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:103)
at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:610)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:770)
at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2823)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2532)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at Application.Vacation.start(Vacation.java:27)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)

здесь исправлена ​​опечатка.

<Button fx:id="DC" layoutX="229.0" layoutY="53.0" mnemonicParsing="false" 
 onAction="#DCbuttonpress" text="Devils CourtHouse" textFill="#ee0707" 
 />enter 

вот исключение после запуска после исправления.

            Executing C:\Users\Kalamar\Documen      
           ts\NetBeansProjects\Vacation\dist  \run1238622098\Vacation 
        .jar using platform C:\Program Files\Java\jdk1.8.0_151\jre/bin/java
       javafx.fxml.LoadException: Error resolving onAction='#DCbuttonpress', 
        either the event handler is not in the Namespace or there is an 
         error in the script 
                file:/C:/Users/Kalamar/Documents/NetBeansProjects/Vacation/d 
               ist/run1238622098/V acation.jar!/Application/Vacation.fxml:17

1 Ответ

0 голосов
/ 27 апреля 2018

Трассировка стека:

javafx.fxml.LoadException: Error resolving 
               onAction='#DCbuttonPpess', either the event handler is 
            not in the Namespace or there is an error in the script.

   file:/C:/Users/Kalamar/Documents/NetBeansProjects/Vacation/di 
       st/run201542084/Vacation.jar!/Application/Vacation.fxml:17

Указывает на проблему с обработчиком onAction, указанным в строке 17 файла Vacation.fxml. Эта строка:

<Button fx:id="DC" ... onAction="#DCbuttonPpess" ... />

Существует явная опечатка в атрибуте onAction: метод, определенный в классе контроллера,

@FXML public void DCbuttonpress(ActionEvent event) {
    /* ... */
}

Так что FXML должен быть

<Button fx:id="DC" ... onAction="#DCbuttonpress" ... />
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...