0

Начал создавать приложение на javafx и столкнулся с ошибкой. Как её исправить?

Вот класс Main:

public class Main extends Application {
/*  Start program!!!  */

FXMLLoader fXMLLoader_MainMenu;

@Override
public void start(Stage stageMainMenu) throws Exception {
    StorageVariables storageVariables=new StorageVariables();

    fXMLLoader_MainMenu=new FXMLLoader();
    fXMLLoader_MainMenu.setLocation(getClass().getResource("MainMenu.fxml"));
    fXMLLoader_MainMenu.setResources(ResourceBundle.getBundle("sample.Properties.MainMenu", new Locale("ru")));

    Parent panel = FXMLLoader.load(getClass().getResource("MainMenu.fxml"));
    Scene scene=new Scene(panel,700,500);
    stageMainMenu.setScene(scene);
    stageMainMenu.setTitle(fXMLLoader_MainMenu.getResources().getString("key_MainMenu_Title")); //titleMainMenu
    stageMainMenu.show();

    System.out.println("   Program start!");
}

public static void main(String[] args) throws Exception{
    launch(args);
}
}

Вот файл fxml:

    <Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"    minWidth="-Infinity" prefHeight="500.0" prefWidth="700.0"  xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"  fx:controller="sample.ControllerProgramGuide">
     <children>
       <ImageView fitHeight="500.0" fitWidth="700.0" pickOnBounds="true" preserveRatio="true">
     <image>
        <Image url="@res/ФонГлавногоОкна.png" />
     </image>
  </ImageView>
  <ImageView fitHeight="45.0" fitWidth="29.0" layoutX="647.0" layoutY="18.0" preserveRatio="true">
     <image>
        <Image url="@res/ЗнакВопроса.png" />
     </image>
  </ImageView>
  <ImageView fx:id="imgBtnQuestion" blendMode="HARD_LIGHT" fitHeight="50.0" fitWidth="50.0" layoutX="635.0" layoutY="16.0" opacity="0.0" pickOnBounds="true" preserveRatio="true">
     <image>
        <Image url="@res/ДляКнопки5050.png" />
     </image>
  </ImageView>
  <Button fx:id="btnQuestion" focusTraversable="false" layoutX="635.0" layoutY="15.0" mnemonicParsing="false" onMouseEntered="#mouseEnteredBtnQUESTION" onMouseExited="#mouseExitedBtnQUESTION" onMousePressed="#inquiryQuestionBtnQUESTION" opacity="0.0" prefHeight="50.0" prefWidth="50.0" />
   <Label layoutX="215.0" layoutY="65.0" prefHeight="35.0" prefWidth="275.0" text="%key_MainMenu_Title" textFill="#070606" >
     <font>
        <Font size="25.0" />
     </font>
   </Label>
 </children>
</Pane>

Ошибка:

No resources specified. /D:/workspace/Assist/out/production/Assist/sample/MainMenu.fxml:29
at javafx.fxml.FXMLLoader$Element.processPropertyAttribute(FXMLLoader.java:308) at javafx.fxml.FXMLLoader$Element.processInstancePropertyAttributes(FXMLLoader.java:200) at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:591) at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2472) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2177) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2069) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2830) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2809) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2795) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2782) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2771) at sample.Main.start(Main.java:24) at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:219)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:182) at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:179)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17) at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67) at java.lang.Thread.run(Thread.java:745)

Exception in Application start method Exception in thread "main" java.lang.RuntimeException: Exception in Application start method at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403) at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47) at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Thread.java:745) Caused by: javafx.fxml.LoadException: No resources specified. at javafx.fxml.FXMLLoader$Element.processPropertyAttribute(FXMLLoader.java:308) at javafx.fxml.FXMLLoader$Element.processInstancePropertyAttributes(FXMLLoader.java:200) at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:591) at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2472) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2177) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2069) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2830) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2809) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2795) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2782) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2771) at sample.Main.start(Main.java:24) at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:219)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:182) at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:179)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17) at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67) ... 1 more

Ошибка появляется лишь при добавлении label текст ключа из файла property.

 text="%key_MainMenu_Title"

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

2
  • а контроллер ControllerProgramGuide почему не кинул?
    – dirkgntly
    23 янв 2016 в 15:54
  • В нем ничего ещё нет
    – dhred
    23 янв 2016 в 15:56

1 ответ 1

1

Я всё понял, добавил инициализацию в контроллере и всё заработало)

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.