Jaimin Modi
Jaimin Modi

Reputation: 1677

How to run single Kotlin class from Android Studio

I am new to Kotlin development and I have created a separate Kotlin class in Android Studio as below :

  class MainClass{

    fun main(args: Array<String>)  {
        println("Hello World");
    }
 }

But, How can I run this kotlin class, and where the output will be generated.

Upvotes: 4

Views: 1639

Answers (2)

Yamini
Yamini

Reputation: 802

Use this code, You will see a run icon near function.

class Test {
        companion object {
            @JvmStatic
            fun main(args: Array<String>) {
                println("Hello test!")
            }
        }
    }

Upvotes: 0

Luis Carino
Luis Carino

Reputation: 66

your main function has to be a top-level function. Try this:

fun main(args: Array<String>)  {
        println("Hello World");
    }

In order to run it, just click on green the icon next to the function name in AS.

Check out this screenshot

Upvotes: 5

Related Questions