Пожалуйста, не запускается проект! - 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
Код:
Листинг программы
  1. import javafx.application.*;
  2. import javafx.scene.*;
  3. import javafx.stage.*;
  4. import javafx.scene.layout.*;
  5. import javafx.scene.control.*;
  6. import javafx.geometry.*;
  7. import javafx.event.*;
  8. import java.io.*;
  9. class MyDictionary {
  10. protected File output_file;
  11. public void AddWord(String word, String translate) {
  12. output_file = new File("E:\\NetBeansProjects\\Dictionary\\src", "Dictionary.txt");
  13. try {
  14. FileWriter file_writer = new FileWriter(output_file, true);
  15. file_writer.write(word + "\t" + translate + "\n");
  16. file_writer.flush();
  17. } catch(IOException e) {
  18. System.out.println("Error!");
  19. }
  20. }
  21. }
  22. class Dictionary extends Application {
  23. public static void main(String[] args) {launch(args);}
  24. public void start(Stage stage) {
  25. MyDictionary dic = new MyDictionary();
  26. stage.setTitle("Dictionary");
  27. FlowPane root = new FlowPane(10, 10);
  28. root.setAlignment(Pos.CENTER);
  29. Scene scene = new Scene(root, 300, 100);
  30. stage.setScene(scene);
  31. MenuBar menu_bar = new MenuBar();
  32. Menu M_file = new Menu("File");
  33. MenuItem MI_exit = new MenuItem("Exit");
  34. M_file.getItems().addAll(MI_exit);
  35. Menu M_dictionary = new Menu("Dictionary");
  36. MenuItem MI_addWord = new MenuItem("Add word");
  37. MenuItem MI_deleteWord = new MenuItem("Delete word");
  38. MenuItem MI_showWords = new MenuItem("Show words");
  39. M_dictionary.getItems().addAll(MI_addWord, MI_deleteWord, MI_showWords);
  40. menu_bar.getMenus().addAll(M_file, M_dictionary);
  41. MI_exit.setOnAction(new EventHandler<ActionEvent> () {
  42. public void handle(ActionEvent action_event) {
  43. Runtime.getRuntime().exit(0);
  44. }
  45. });
  46. MI_addWord.setOnAction(new EventHandler<ActionEvent> () {
  47. public void handle(ActionEvent action_event) {
  48. TextField text_field_word = new TextField();
  49. TextField text_field_translate = new TextField();
  50. text_field_word.setPromptText("Enter word");
  51. text_field_translate.setPromptText("Enter translate");
  52. root.getChildren().addAll(text_field_word, text_field_translate);
  53. text_field_translate.setOnAction(new EventHandler<ActionEvent> () {
  54. public void handle(ActionEvent action_event) {
  55. dic.AddWord(text_field_word.getText(), text_field_translate.getText());
  56. }
  57. });
  58. }
  59. });
  60. root.getChildren().add(menu_bar);
  61. stage.show();
  62. }
  63. }

Решение задачи: «Пожалуйста, не запускается проект!»

textual
Листинг программы
  1. public class Dictionary extends Application

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

14   голосов , оценка 3.929 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут