【问题标题】:Class names, 'Introductions', are only accepted if annotation processing is explicitly requested仅当显式请求注释处理时才接受类名“介绍”
【发布时间】:2018-06-23 18:23:01
【问题描述】:

我在尝试编译一个简单的 Java 程序时收到此错误消息。我知道 Stack 上已经有这个问题,但是解决方案(我在编译程序时忘记包含 .java 后缀)仍然对我不起作用。这是程序:

import java.io.Console;

    public class Introductions {

        public static void main(String[] args) {
            Console console = System.console();
            // Welcome to the Introductions program!  Your code goes below here
            String firstName = "Paul";
            console.printf("Hello, my name is %s\n", firstName);
            console.printf("%s this is learning how to write Java\n", firstName);
      }
    }

【问题讨论】:

  • 你用什么命令编译程序?
  • 'javac Introductions.java' 编译它,然后 'javac Introductions' 运行它
  • 你需要使用java来运行它。

标签: java compiler-errors runtime-error


【解决方案1】:

编译 Java 程序和运行 Java 程序有两种不同的命令。您收到一个错误,这意味着编译程序的命令 (javac) 收到了不包含 .java 后缀的参数,正如 other questions 关于此错误所述。

但是,听起来您使用javac Introductions.java 进行了正确编译。你的问题其实出在第二步,运行程序。运行 javac Introductions 告诉 Java 你想再次编译,所以它正确地指出你忘记了扩展。

但是你不想编译第二次;你想运行它!这使用java 而不是javac

编译:javac Introductions.java

运行:java Introductions

另请参阅How do I run a Java program from the command line on Windows?(尽管这并不是真正的 Windows 特定的)。

【讨论】:

    猜你喜欢
    • 2011-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-28
    • 2022-01-08
    • 2014-03-06
    相关资源
    最近更新 更多