M
M
MarkusEfr2018-08-01 09:00:47
Java
MarkusEfr, 2018-08-01 09:00:47

How to get rid of NoClassDefFoundError after building JavaFX project in Eclipse?

I'm learning Java, I created a test project "study schedule" to get acquainted with the work in Eclipse (OS Linux Mint) and recall the basics. Setting up and developing the project went well, but after building the jar does not start, but gives an error. Please help me understand what it is and how to fix it? 5b614a7f02866817652009.png5b614a8e15860530065615.png5b614a976f385110409434.png
The project structure in the IDE, the work and the error are shown in the images.
Project Files:
Education.java inherits from Application and contains the program's main.

package application;
  
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;


public class Education extends Application {
  @Override
  public void start(Stage primaryStage) {
      try {
        Parent root = FXMLLoader.load(getClass()
                      .getResource("Scene.fxml"));
   
              primaryStage.setTitle("My Education");
              primaryStage.setScene(new Scene(root));
              primaryStage.show();
      } catch(Exception e) {
        e.printStackTrace(); }
  }
  
  public static void main(String[] args) {
    launch(args);
  }
}

Controller.java contains methods for selecting the day of study and declaring interface elements
package application;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.MenuButton;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextArea;

public class Controller implements Initializable {
  @FXML
  private MenuButton Days = new MenuButton();
  @FXML
  private MenuItem day1 = new MenuItem();
  @FXML
  private MenuItem day2 = new MenuItem();
  @FXML
  private MenuItem day3 = new MenuItem();
  @FXML
  private MenuItem day4 = new MenuItem();
  @FXML
  private MenuItem day5 = new MenuItem();
  @FXML
  private TextArea text = new TextArea();
  
  
  @Override
  public void initialize(URL location, ResourceBundle resources) {

  }
  @FXML
  public void chooseDay1(ActionEvent event) {
         System.out.println("Button Clicked!");  
         text.setText("");
         String [] Day = new String [] {"День 1","Алгоритмы на Java. 1 час.","Изучаем JavaEE. 1 час.","Отдых. Еда.","Паттерны проектирования. 40 мин.", "Изучение ООП. 40 мин."} ;
          // Show in VIEW
           for (String i:Day) {
         text.appendText(i+"\n"); 
         }
    }@FXML
  public void chooseDay2(ActionEvent event) {
         System.out.println("Button Clicked!");  
         text.setText("");
         String [] Day = new String [] {"День 2","Рефакторинг. 30 мин","Изучаем JavaEE. 1 час","Отдых. Еда.","Структуры данных. 30 мин.", "Изучение ООП. 30 мин."} ;
          // Show in VIEW
        for (String i:Day) {
         text.appendText(i+"\n"); 
         }
 } @FXML
  public void chooseDay3(ActionEvent event) {
         System.out.println("Button Clicked!");  
         text.setText("");
         String [] Day = new String [] {"День 3","Алгоритмы на Java. 1 час","Изучаем JavaEE. 1 час","Отдых. Еда.","Java 8 Полное руководство. 40 мин.", "Изучение ООП. 30 мин."} ;
          // Show in VIEW
        for (String i:Day) {
         text.appendText(i+"\n"); 
         }
 } @FXML
  public void chooseDay4(ActionEvent event) {
         System.out.println("Button Clicked!");  
         text.setText("");
         String [] Day = new String [] {"День 4","Рефакторинг. 30 мин.","Изучаем JavaEE. 1 час","Отдых. Еда.","Паттерны проектирования. 30 мин.", "Коллекции в Java. 30 мин."} ;
          // Show in VIEW
        for (String i:Day) {
         text.appendText(i+"\n"); 
         }
 } @FXML
  public void chooseDay5(ActionEvent event) {
         System.out.println("Button Clicked!");  
         text.setText("");
         String [] Day = new String [] {"День 5","Алгоритмы на Java. 40 мин.","Изучаем JavaEE. 1 час","Отдых. Еда.","Java 8 Полное руководство. 40 мин.", "Изучение ООП. 30 мин."} ;
          // Show in VIEW
        for (String i:Day) {
         text.appendText(i+"\n"); 
         }
 }
}

Scene.fxml describes the form of the program's interface.
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.text.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="325.0" prefWidth="397.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller">
   <children>
      <MenuButton fx:id="Days" layoutX="28.0" layoutY="19.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="134.0" text="Choose day">
        <items>
            <MenuItem fx:id="day1" mnemonicParsing="false" onAction="#chooseDay1" text="Day 1" />
            <MenuItem fx:id="day2" mnemonicParsing="false" onAction="#chooseDay2" text="Day 2" />
          <MenuItem fx:id="day3" mnemonicParsing="false" onAction="#chooseDay3" text="Day 3" />
          <MenuItem fx:id="day4" mnemonicParsing="false" onAction="#chooseDay4" text="Day 4" />
            <MenuItem fx:id="day5" mnemonicParsing="false" onAction="#chooseDay5" text="Day 5" />
        </items>
         <font>
            <Font name="DejaVu Sans Bold" size="13.0" />
         </font>
      </MenuButton>
      <TextArea fx:id="text" editable="false" layoutY="57.0" opacity="0.8" prefHeight="242.0" prefWidth="397.0" AnchorPane.bottomAnchor="26.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="57.0">
         <font>
            <Font name="KacstOffice" size="17.0" />
         </font></TextArea>
      <ImageView fitHeight="52.0" fitWidth="176.0" layoutX="221.0" layoutY="3.0" pickOnBounds="true" AnchorPane.bottomAnchor="270.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="3.0">
         <image>
            <Image url="@../../img/education.png" />
         </image>
      </ImageView>
      <Label layoutX="129.0" layoutY="302.0" prefHeight="19.0" prefWidth="140.0" text="Week train schedule" AnchorPane.bottomAnchor="4.0" AnchorPane.leftAnchor="129.0" AnchorPane.rightAnchor="128.0" />
   </children>
</AnchorPane>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
EVGENY T., 2018-08-01
@MarkusEfr

Java does not see the javafx libraries when starting the application, but when compiling it does.
Deal with it. You can directly specify the path to javafx in the classpath parameter at startup.

M
MarkusEfr, 2018-08-01
@MarkusEfr

In the libraries of the project javafx is present, I thought it should be together with the running program in this case. Or does the client have to have exactly the right jdk installed? 5b615f1d7979d527223631.png
I installed jdk8 with which I compiled and the program began to work. Thank you.
5b61b11f9da56786455849.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question