0

I am trying to use vscode to coding with kotlin. After installing kotlin language and code runner extensions on vscode and install kotlin by snap on my mxlinux:

alt@mx:~
$ snap list
Name    Version    Rev    Tracking       Publisher   Notes
core    16-2.51.4  11606  latest/stable  canonical✓  core
kotlin  1.5.30     61     latest/stable  jetbrains✓  classic
alt@mx:~

alt@mx:~
$ snap version
snap    2.51.4
snapd   2.51.4
series  16
debian  10
kernel  4.19.0-17-amd64
alt@mx:~

I wrote this code on vscode:

fun main(args: Array<String>) {
    var string = "Hello Students!"
    val age: Int = 23
    println(string)
    println(age)
}

and run I got result and error:

[Running] cd "/mnt/Project/Android/Practise/Kotlin/Practices/tuto1/" && kotlinc HelloWorld.kt -include-runtime -d HelloWorld.jar && java -jar HelloWorld.jar
HelloWorld.kt:1:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^
Hello Students!
23

[Done] exited with code=0 in 12.147 seconds

And In Ide there are a lots of error: enter image description here

4
  • 1
    "parameter 'args' is never used" is not an error. It clearly says that it is a warning. Commented Sep 9, 2021 at 9:01
  • Also, which extension did you install? Can you post the links? I used this one and it works. The error that you got in VS code suggests that you need to specify the -include-runtime option in somewhere. Commented Sep 9, 2021 at 9:15
  • I installed marketplace.visualstudio.com/items?itemName=fwcd.kotlin and marketplace.visualstudio.com/… extension Commented Sep 9, 2021 at 9:24
  • Have I add -include-runtime somewhere? where? Commented Sep 9, 2021 at 9:24

1 Answer 1

2

and run I got result and error

That is not an error. As it clearly says, it is a warning. Warnings don't stop your code from compiling and running. If you don't want the warning, you can pass the -nowarn compiler option to kotlinc. If you do want the warning to stop your code from compiling, pass -Werror instead. See list of compiler options here.

And In Ide there are a lots of error

From the description of the Kotlin VSCode extension, you are supposed to open a Gradle/Maven project (see my answer here for how to create one), and "support for Kotlin source files with a standalone compiler is experimental". I've also found this issue that points out that even if you don't use Gradle or Maven, you still have to open a folder.

So rather than opening the file like this:

$ code MyProject/HelloWorld.kt

You should open it like this:

$ code MyProject

In other words, open the folder that contains the kotlin file.

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, I need gradle

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.