nosuchmethoderror

3z6pesqy  于 2021-07-12  发布在  Java
关注(0)|答案(1)|浏览(403)

我用java制作了一个小应用程序,它在intellij idea中运行得很好,但是一旦我尝试将它导出到jar文件并尝试运行它,就会出现以下错误:

  1. Exception in thread "main" java.lang.NoSuchMethodError: nu.apiary.PF2.Building.<init>(ILjava/lang/String;III)V
  2. at nu.apiary.RMS.Main.main(Main.java:13)

我的所有依赖项都包含在jar文件中(我已经和winrar进行了检查)。。。
此方法出错:

  1. public static void main(String[] args) {
  2. try {
  3. building = new Building(Integer.parseInt(args[0]), args[1], 0, 0, 0);
  4. } catch (Exception e) {
  5. System.err.println("Incorrect building name entered!");
  6. System.err.println("Closing now!");
  7. System.exit(-1);
  8. }
  9. if(args.length == 2)
  10. server = new Server(8998);
  11. else if(args.length == 3)
  12. server = new Server(Integer.parseInt(args[2]));
  13. else if(args.length < 2 || args.length > 3) {
  14. System.err.println("Incorrect amount of arguments, correct usage:");
  15. System.err.println("rms-[version] <height> <name> [port]");
  16. System.err.println("Closing now!");
  17. System.exit(-1);
  18. }
  19. serverThread = new Thread(server);
  20. serverThread.start();
  21. }

在这一行:

  1. building = new Building(Integer.parseInt(args[0]), args[1], 0, 0, 0);

我用这个命令运行它:

  1. java -jar rms.jar 1 data/home#
voj3qocg

voj3qocg1#

我没有发现问题,但是我已经解决了:)

  1. 1. In Intellij I exported the project to Eclipse. (File --> Export to Eclipse)
  2. 2. I then opened the project in eclipse.
  3. 3. I created a new run configuration.
  4. 4. I then exported the project as a runnable jar file. (File --> Export... --> Java --> Runnable Jar --> Complete the export dialog)

相关问题