0

I wrote a simple kotlin code in KotlinMain.kt :

fun main(args: Array<String>) {
    println("Hello world from Kotlin.")
}

But when I run this method, Android Studio throws

Exception in thread "main" java.lang.ClassNotFoundException: com.li.sample.KotlinMainKt
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:107)

But When I write this code in a Java file, it works OK.

How to solve this problem ?

Benjith Mathew
  • 1,211
  • 1
  • 11
  • 23
L. Swifter
  • 3,179
  • 28
  • 52
  • 1
    Have you take a look here - https://stackoverflow.com/questions/45891317/classnotfoundexception-error-for-kotlin-non-android-project-on-android-studio – vinS Dec 15 '17 at 03:58
  • 1
    You can't run Kotlin main function in Android Studio. Studio doesn't support that (not sure if this was intentional or not). You need Injellij Idea for this. – Henry Dec 15 '17 at 04:38

0 Answers0