gpt4 book ai didi

java - 错误: Could not find or load main class (Something to do with classpath/environment variables)

转载 作者:太空宇宙 更新时间:2023-11-04 06:54:53 25 4
gpt4 key购买 nike

这个问题已经被问过无数次了,但我还没有得到解决方案。我的代码:

import java.util.Scanner;
import java.io.*;

public class Reverse
{
public static void main(String[] args)
{
File myFile = new File(args[0]);
try
{
Scanner input = new Scanner(myFile);
String message = "";
while(input.hasNext())
{
message = input.nextLine() + message;
}

System.out.println(message);
input.close();
}
catch(FileNotFoundException e)
{
System.exit(1);
}
}
}

详细信息:

  • 通过 Mac 上的 Eclipse 进行编码

  • 使用 javac Reverse.java 然后 java Reverse.java 在命令行上运行(编辑:java Reverse 有效)

- 这与类路径有关,但我不知道我应该做什么

我没有对类路径做任何事情,所以感谢任何帮助。

编辑:我现在的问题是, java -classpath .逆向工作?我不太明白 -classpath 标签和 '.'标签。

最佳答案

正如 Pradeep 的评论所提到的,您需要运行 java Reverse 而不是 java Reverse.java。否则,它将查找名为 Reverse.java 的类,该类不存在。您的类(class)名为 Reverse

为了回答已编辑的问题,java -classpath .基本上告诉java使用当前工作目录.作为classpath的一部分。 classpath 是 java 查找要加载和运行的类的路径。

关于java - 错误: Could not find or load main class (Something to do with classpath/environment variables),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22889904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com