简体   繁体   English

为什么我的代码没有在 VisuaStudioCode 中运行?

[英]Why isn't my code running in VisuaStudioCode?

I downloaded VS code and tried to run a basic java code in it.我下载了 VS 代码并尝试在其中运行基本的 java 代码。 I have already installed JDK in my system, set the environment variables too and also downloaded the red hat extension for java.我已经在我的系统中安装了 JDK,也设置了环境变量,还下载了 java 的红帽扩展。 The code runs smoothly in cmd prompt.代码在 cmd 提示符下运行流畅。 But when i run the code in VS it says "File not found in the output and "Hello.java is a non project file".但是当我在 VS 中运行代码时,它会显示“在 output 中找不到文件,并且“Hello.java 是一个非项目文件”。

The same problem is arising in C program too.同样的问题也出现在 C 程序中。 What should i do to resolve this?我应该怎么做才能解决这个问题?

[Image] [1]: https://i.stack.imgur.com/hh8o0.jpg [图片] [1]: https://i.stack.imgur.com/hh8o0.jpg

In some cases, launch.json cwd configuration is causing these errors.在某些情况下, launch.json cwd 配置会导致这些错误。 Could you please also share launch.json file.您能否也分享一下launch.json文件。

This thread might help too.这个线程也可能有帮助。

File not found in Output.在 Output 中找不到文件。

That's because you're running tempCodeRunnerfile.java but hello.java was opened.那是因为您正在运行tempCodeRunnerfile.javahello.java已打开。 Also you use the extension Code Runner , so the result will be shown in Output.您还使用扩展Code Runner ,因此结果将显示在 Output 中。

After cleaning java workspace, open tempCodeRunnerfile.java and click the triangle button( Run Code ) to try again.清理 java 工作区后,打开tempCodeRunnerfile.java并单击三角形按钮(运行代码)重试。

It's recommended that using the integrated Terminal to run the code instead of Code Runner.建议使用集成终端而不是 Code Runner 来运行代码。

Hello.java is a non project file. Hello.java 是一个非工程文件。

This couldn't be called as an error but just a warning.这不能称为错误,而只是警告。 Press Ctrl+Shift+P to open Command Platte and choose Java: Create Java Project .Ctrl+Shift+P打开 Command Platte 并选择Java:创建 Java 项目 Coding in project, this warning won't be shown.在项目中编码,不会显示此警告。

Gif tutorial and more information please refer to Creating a source code file . Gif 教程和更多信息请参阅创建源代码文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM