I am trying to run Scala in VS Code, a simple hello world statement, but I get this output:
PS C:\Users\thmga\OneDrive\Documents\Notebook\vscode_test> scala "c:\Users\thmga\OneDrive\Documents\Notebook\vscode_test\test.scala"
Exception in thread "main" dotty.tools.scripting.StringDriverException: No main methods detected for [c:\Users\thmga\OneDrive\Documents\Notebook\vscode_test\test.scala]
at dotty.tools.scripting.StringDriverException$.apply(StringDriver.scala:47)
at dotty.tools.scripting.Util$.detectMainClassAndMethod(Util.scala:51)
at dotty.tools.scripting.ScriptingDriver.compileAndRun(ScriptingDriver.scala:28)
at dotty.tools.scripting.Main$.main(Main.scala:45)
at dotty.tools.MainGenericRunner$.run$1(MainGenericRunner.scala:249)
at dotty.tools.MainGenericRunner$.main(MainGenericRunner.scala:268)
at dotty.tools.MainGenericRunner.main(MainGenericRunner.scala)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at coursier.bootstrap.launcher.a.a(Unknown Source)
at coursier.bootstrap.launcher.Launcher.main(Unknown Source)
The code:
@main def hello(): Unit =
println("Hello, World!")
I tried with the file named "test.sc" and "test.scala". When I used "test.scala" the icon of Scala appeared beside the file.
I installed Scala Syntax (official)
and Scala (Metals)
. Anyone any clue? Thanks.