gpt4 book ai didi

java - 为什么intellij中的所有程序都会导致找不到类错误

转载 作者:太空宇宙 更新时间:2023-11-04 09:23:23 24 4
gpt4 key购买 nike

所以,我试图运行一个源代码,我得到了 following error

这是我的 directory folder据我所知,定义类和目录的名称没有问题。我尝试运行的代码是 Deitel Java 如何编程的示例。

package Concurrency;

import java.security.SecureRandom;
import java.text.NumberFormat;
import java.time.Duration;
import java.time.Instant;
import java.util.Arrays;

public class SortComparison {
public static void main(String[] args) {

SecureRandom generator = new SecureRandom();

int[] array1 = generator.ints(15_000_000).toArray();
int[] array2 = new int[array1.length];
System.arraycopy(array1, 0, array2, 0, array1.length);

System.out.println("Starting sort");
Instant sortStart = Instant.now();
Arrays.sort(array1);
Instant sortEnd = Instant.now();

long sortTime = Duration.between(sortStart, sortEnd).toMillis();
System.out.printf("Total time in milliseconds: %d%n%n", sortTime);

System.out.println("Starting parallelSort");
Instant parallelSortStart = Instant.now();
Arrays.parallelSort(array2);
Instant parallelSortEnd = Instant.now();

long parallelSortTime =
Duration.between(parallelSortStart, parallelSortEnd).toMillis();
System.out.printf("Total time in milliseconds: %d%n%n",
parallelSortTime);

String percentage = NumberFormat.getPercentInstance().format(
(double) sortTime / parallelSortTime);
System.out.printf("%nSort took %s more time than parallelSort%n",
percentage);
}
}

然后我尝试将我使用的JDK版本从版本12更改为版本11,然后其他项目也发生了同样的事情。

事情甚至变得更好:)))。我尝试创建一个简单的 hello world 项目,然后那里发生了同样的事情。是Intellij Idea有问题还是我的java版本有问题?现在,我的 JDK 版本为 13。我应该重新安装 Intellij 还是有其他选择?

最佳答案

  1. 确保在执行运行/调试配置之前构建项目,或者运行配置在启动前部分中有Make步骤。

  2. 确保在使用模块的类路径下拉列表中指定了正确的模块

  3. 检查module's compiler output directory确实有这个编译类。 IDE 在构建项目时将类复制到那里。

关于java - 为什么intellij中的所有程序都会导致找不到类错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58041661/

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