I started off with the tutorial for learning Kotlin in IntelliJ
.When I tried running the example i.e
fun main(args: Array) {
prin
Sometimes in similar situations (I don't think it is your problem because your case is very simple) it's worth to check kotlin file package.
If you have Kotlin file within the same package and put there some classes and missed the package declaration it looks inside the IntelliJ that you have classes in the same package but without definition of package the IntelliJ shows you:
Error:(5, 5) Kotlin: Unresolved reference: ...
I had this issue because the linter was printing that my object was an instance of Foo
whereas the compiler couldn't define its type and consider it was an Any
object like (It was more complex in my case, the linter show error in below code but the idea is here) :
class Foo {
val bar: Int = 0
}
fun test(): Any {
return Foo()
}
val foo = test()
foo.bar // <-- Linter consider that foo is an Instance of Foo but not the compiler because it's an Any object so it show the error at compilation.
To fix it I had to cast my object :
val foo = test() as Foo
Ran into this issue. I had to add the following to my build.grade:
apply plugin: 'kotlin-android'
A possible solution for standalone Kotlin projects is to include Kotlin standard libs explicitliy inside the root project.
To do that in IntelliJ IDEA:
Happened to me today.
My issue was that I had too many tabs open (I didn't know they were open) with source code on them.
If you close all the tabs, maybe you will unconfuse IntelliJ into indexing the dependencies correctly
Had the same with IDEA 14.1.5, Kotlin v.1.0.0-beta-1038-IJ141-17.
Kotlin gets its own list entry (like Java) when creating new project, but the only working config was:
New | Project | Java | "Kotlin (Java)" (make sure you have Project SDK configured, too)
use library: Create, "Copy to: lib".