What is the mainclass for Kotlin? Why do I get "Unknown mainclass"?

Modified on Tue, 27 Apr 2021 at 01:36 PM

The mainclass is the class containing the entry point (main method) of your program. It is a method that looks like this:

fun main(args : Array<String>)


Note that in Kotlin, a file "fuzzy.kt" containing the main method gets compiled to "FuzzyKt.class", so the mainclass is "FuzzyKt".


As you can submit multiple classes, there can potentially be multiple such methods. Therefore
you need to specify which class contains the main method we should use. Note that the mainclass
must contain the full name of the class. If you declare a package, it must be included (or
we will not find your class). For example, if your class name is "SolutionKt" and it is in package "fuzzy"
your mainclass should be "fuzzy.SolutionKt".


In Kotlin it is possible to write a program with an implicit class declaration. If you do not write "public class {Name}Kt" at some point in your program, Kotlin will use the filename to generate a class declaration. For example, if your file is named "foo.kt" the generated class declaration will be "public class FooKt".



Specifying the wrong mainclass will give you a Compile Error telling you what happened.


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article