java - 使用 VSCode 并获得 NoClassDefFoundError
问题描述
我通常使用像 IntelliJ 这样的 IDE,但我正在尝试迁移到 VSCode,但我不明白为什么我在 IntelliJ 上工作的项目运行良好,但是当我在 VSCode 中打开该项目时出现该错误。我已经查看了这个问题的其他答案,但他们都提到了我不太熟悉的诸如 bin、src 和 classpath 之类的东西。我想那是如果你通过 cmd 运行 java 但我没有。我该如何解决这个问题?
我在 D:\Antonio\Documents\GitLab\ProjectEuler-Java\Solved_Problems 中的文件
package Solved_Problems;
class Problem_001_MultiplesOf3And5{
// Multiples of 3 and 5
/*
*
* If we list all the natural numbers below 10 that are multiples of 3 or 5, we
* get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the
* multiples of 3 or 5 below 1000.
*
*/
public static void main(String[] args) {
int totalsum = 0;
for (int i = 1; i < 1000; i++) {
if ((i % 3 == 0) || (i % 5 == 0))
totalsum += i;
}
System.out.println(totalsum);
}
}
输出:
Error: Could not find or load main class Problem_001_MultiplesOf3And5
Caused by: java.lang.ClassNotFoundException: Problem_001_MultiplesOf3And5
[Done] exited with code=1 in 0.835 seconds
解决方案
我不知道这是否为您解决,但我也花了很长时间才弄清楚。我做了什么:
首先,我使用 Java 插件创建了一个 launch.json 文件。
然后我将mainClass
变量编辑为myfilename.java
. myfilename
如果我只输入mainClass
变量,我会遇到和你一样的错误。
作为最后一步,您需要修改classPath
以包含项目所需的任何 .jar。
推荐阅读
- path - HAProxy - 无法更改后端服务器中的路径
- php - PHPCS 的 Git Pre-Commit 钩子在 Laravel 的 Windows 中给了我错误
- r - Shinyapps 部署错误:应用程序依赖于包“dplyr”但未安装
- python - 查找数据框中的所有转换
- react-native - 如何使用样式在本机反应中创建甘特图
- visual-studio - 在 VS Toolbox 中以不同的 DisplayName 显示组件
- apache-flink - StreamTableEnvironment 是否能够针对批处理流运行?
- visual-studio-code - 检查项目文件夹中所有资产的大小写敏感及其在程序中的声明
- flutter - 无法修复在颤振中不正确使用 ParentDataWidget
- r - 将标签放在 circlize 和弦图中的图例颜色条内