Пожалуйста, не запускается проект! - Java
Формулировка задачи:
Компилятор пишет сборка завершена успешно, но при запуске вот что выводит:
Код:
Executing E:\NetBeansProjects\Dictionary\dist\run953642836\Dictionary.jar using platform C:\Program Files\Java\jdk1.8.0_131\jre/bin/java
Exception in Application constructor
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Unable to construct Application instance: class Dictionary
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:907)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoSuchMethodException: Dictionary.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.getConstructor(Class.java:1825)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:818)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(WinApplication.java:191)
... 1 more
Java Result: 1
Листинг программы
- import javafx.application.*;
- import javafx.scene.*;
- import javafx.stage.*;
- import javafx.scene.layout.*;
- import javafx.scene.control.*;
- import javafx.geometry.*;
- import javafx.event.*;
- import java.io.*;
- class MyDictionary {
- protected File output_file;
- public void AddWord(String word, String translate) {
- output_file = new File("E:\\NetBeansProjects\\Dictionary\\src", "Dictionary.txt");
- try {
- FileWriter file_writer = new FileWriter(output_file, true);
- file_writer.write(word + "\t" + translate + "\n");
- file_writer.flush();
- } catch(IOException e) {
- System.out.println("Error!");
- }
- }
- }
- class Dictionary extends Application {
- public static void main(String[] args) {launch(args);}
- public void start(Stage stage) {
- MyDictionary dic = new MyDictionary();
- stage.setTitle("Dictionary");
- FlowPane root = new FlowPane(10, 10);
- root.setAlignment(Pos.CENTER);
- Scene scene = new Scene(root, 300, 100);
- stage.setScene(scene);
- MenuBar menu_bar = new MenuBar();
- Menu M_file = new Menu("File");
- MenuItem MI_exit = new MenuItem("Exit");
- M_file.getItems().addAll(MI_exit);
- Menu M_dictionary = new Menu("Dictionary");
- MenuItem MI_addWord = new MenuItem("Add word");
- MenuItem MI_deleteWord = new MenuItem("Delete word");
- MenuItem MI_showWords = new MenuItem("Show words");
- M_dictionary.getItems().addAll(MI_addWord, MI_deleteWord, MI_showWords);
- menu_bar.getMenus().addAll(M_file, M_dictionary);
- MI_exit.setOnAction(new EventHandler<ActionEvent> () {
- public void handle(ActionEvent action_event) {
- Runtime.getRuntime().exit(0);
- }
- });
- MI_addWord.setOnAction(new EventHandler<ActionEvent> () {
- public void handle(ActionEvent action_event) {
- TextField text_field_word = new TextField();
- TextField text_field_translate = new TextField();
- text_field_word.setPromptText("Enter word");
- text_field_translate.setPromptText("Enter translate");
- root.getChildren().addAll(text_field_word, text_field_translate);
- text_field_translate.setOnAction(new EventHandler<ActionEvent> () {
- public void handle(ActionEvent action_event) {
- dic.AddWord(text_field_word.getText(), text_field_translate.getText());
- }
- });
- }
- });
- root.getChildren().add(menu_bar);
- stage.show();
- }
- }
Решение задачи: «Пожалуйста, не запускается проект!»
textual
Листинг программы
- public class Dictionary extends Application
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д