Why PowerShell shows 'Cannot find symbol' error But VS Code Java Process Console runs it nicely?

huangapple go评论100阅读模式
英文:

Why PowerShell shows 'Cannot find symbol' error But VS Code Java Process Console runs it nicely?

问题

你好

我已经在Java中为我的大学编写了一个演示GUI项目。我在VS Code中进行开发工作。我为这个项目编写的代码在我使用VS Code的运行按钮运行时运行得很好。当我在VS Code中运行它时,输出如下 -

Why PowerShell shows 'Cannot find symbol' error But VS Code Java Process Console runs it nicely?

但是,当我尝试从Windows PowerShell或Linux终端执行相同的应用程序(代码)时,它显示了这个错误。

Why PowerShell shows 'Cannot find symbol' error But VS Code Java Process Console runs it nicely?

请问有人可以告诉我为什么会发生这种情况吗?

提前致谢。

**PS:**我已经尝试从不同的文件夹运行它,但仍然不起作用。我已经为存储库中的每个类文件使用了包声明和正确的导入。

英文:

Hello,

I have written a demo GUI project in java for my university. I use VS code for development works. The codes I wrote for this project runs nicely when I run it using the VS Code Run button. This is the output when I run it in VS Code -

Why PowerShell shows 'Cannot find symbol' error But VS Code Java Process Console runs it nicely?

But when I am trying to execute the same App (Code) from the Windows PowerShell or Linux terminal it shows this error.

Why PowerShell shows 'Cannot find symbol' error But VS Code Java Process Console runs it nicely?

Can anyone please tell me why this is happening ?

Thanks in advance.

**PS: **I have tried running it from different folders but still doesn't work. I have used the package declaration and import correctly for each class files in the repo.

答案1

得分: 1

运行 Java 文件在终端时,Java 扩展将自动编译您导入的包。如下所示的屏幕截图,转到下划线处标记的目录,您会找到 App.class 文件以及 mains 文件夹中的 home.class 文件。

但是,当您在外部 PowerShell 中使用 javac App.java 时,没有像在 VS Code 中那样的自动编译过程,所以首先您需要编译导入的包:

然后您可以成功运行它。

英文:

When you run java file in terminal, Java extension will automatically compile the packages you import. Like the screenshot showing, turn to the directory red underlined, you'll find App.class file as well as home.class in folder mains.

Why PowerShell shows 'Cannot find symbol' error But VS Code Java Process Console runs it nicely?

But when you use javac App.java in external PowerShell, there's no process like the one in VS Code, so first you should compile packages imported:

Why PowerShell shows 'Cannot find symbol' error But VS Code Java Process Console runs it nicely?

Then you can run it successfully.

huangapple
  • 本文由 发表于 2020年9月16日 01:06:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/63906724.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定