I have a project with Java and Kotlin, which I am able to successfully run and build. However, when I open the project in IntelliJ, I see the same error in many of the project files.
The error is "Cannot access class 'java.lang.String'. Check your module classpath for missing or conflicting dependencies"
See the error in the image attached:
Another example of an error occurs when initializing a Kotlin MultiPlatform Mobile project:
cannot access 'java.lang.Object' which is a supertype of 'org.gradle.api.artifacts.dsl.RepositoryHandler'. Check your module classpath for missing or conflicting dependencies
What is the source of this error? How can I fix it?
If your project is set with a JDK, then probably IDE (Intellij) does not have JDK set but your built application could run just fine with the required JVM. Open the project structure window (ctrl + shift + alt +s) and select the java version you created your project with.
In our project we encountered this because we added the same directory to both production and the test sources.
sourceSets {
main.java.srcDirs += 'src/main/kotlin/'
main.java.srcDirs += 'build/generated/source/protos/main/java'
test.java.srcDirs += 'src/test/kotlin/'
test.java.srcDirs += 'build/generated/source/protos/main/java'
}
Removing the duplicate from the test sources fixed the problem.
sourceSets {
main.java.srcDirs += 'src/main/kotlin/'
main.java.srcDirs += 'build/generated/source/protos/main/java'
test.java.srcDirs += 'src/test/kotlin/'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With