Check your module classpath for missing or conflicting dependencies

JavaKotlinIntellij IdeaJvmKotlin Multiplatform

Java Problem Overview


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: enter image description here


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?

Java Solutions


Solution 1 - Java

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.

Solution 2 - Java

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/'
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMadLaxView Question on Stackoverflow
Solution 1 - Javadexter2305View Answer on Stackoverflow
Solution 2 - JavaJesse WilsonView Answer on Stackoverflow