I'm using Android Studio 3.2 and trying to run a scratch file, but can't find where println is output.
Contents of my scratch file:
fun main(args: Array<String>) {
println("Hello, world!")
}
But the output window is missing "Hello, world!"
Am I looking in the wrong place?
From the main menu, select File | New | Scratch File or press Ctrl+Alt+Shift+Insert , then select Kotlin.
From the main menu, select File | New | Scratch File or press Ctrl+Alt+Shift+Insert . Select the language of the scratch file. Scratch files of the same type are automatically numbered and added to the Scratches and Consoles directory of the Project view. in the gutter or press Shift+F10 .
Location of REPL in Android Studio: You can find REPL under the Tool -> Kotlin -> Kotlin REPL menu.
IntelliJ IDEA and Android Studio support Kotlin scratch files and worksheets. Scratch files (or just scratches) let you create code drafts in the same IDE window as your project and run them on the fly.
A .kts
file doesn't require a main
function. You can add the print statement at the top level.
This would explain the warning about args
being unused, since main
is never invoked.
A script is a Kotlin source file (.kts) with top level executable code.
Using the command line to run scripts
Simply remove the main function eg: main(args: Array){ } but leave the inside contents of main such as function calls in your scratches file eg: callingFun("PassingString"). Then hit the run button of the scratches file and then output should show up to the right side of the relevant lines of code. screen shot
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With