【问题标题】:I don't understand why I get the error message: Error: Could not find or load main class World Caused by: java.lang.ClassNotFoundException: World我不明白为什么会收到错误消息:错误:无法找到或加载主类 World 原因:java.lang.ClassNotFoundException: World
【发布时间】:2021-08-13 23:57:09
【问题描述】:
import java.util.Scanner;
public class World {

    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);
        System.out.println("Hello. What is your name? ");
        String input = scnr.next();
        System.out.println("It's nice to meet you, " + input + ". How old are you?");
        String age = scnr.next();
        System.out.println("I see that you are still quite young at only " + age + ".");
        System.out.println("Where do you live? ");
        String city = scnr.next();
        System.out.println("Wow! I've always wanted to go to " + city + ". Thanks for chatting with me. Bye!");
    }


}

我正在使用 IntelliJ,尽管我收到错误消息:错误:无法找到或加载主类 World 原因:java.lang.ClassNotFoundException: World

【问题讨论】:

  • 我怀疑你没有给文件命名:World.java(区分大小写)所以没有找到应该绑定到文件的类。

标签: java intellij-14 mainclass


【解决方案1】:

检查您的课程是否在一个包中。如果没有包,您的代码将无法运行。否则,如果您有其他包含主要方法的类,它将无法工作,因为您不能拥有超过 1 个主要方法

【讨论】:

    猜你喜欢
    • 2013-10-30
    • 1970-01-01
    • 2020-12-10
    • 1970-01-01
    • 2022-06-17
    • 1970-01-01
    • 1970-01-01
    • 2020-09-03
    • 1970-01-01
    相关资源
    最近更新 更多