it fixes the issue The compilation fails because your Java class is not in a directory that matches its package statement. While Kotlin allows you to put classes in any directories regardless of the package they're in, Java requires you to put each file in a package that corresponds to its directory. This requirement applies to mixed-language projects as well. To fix the error, move JavaFoo.java to src/main/java/com/example/kotlindemo.
Got Unresolved reference: setText when convert java to kotlin
Hope this helps I was able to find a solution for this. Turns out, (and I don't know the reason why), but after upgrading the Gradle version and Kotlin plugin, the older version of a library was causing some kind of interference. I updated