I try to run the class from the green arrow in IntelliJ and I get the "Could not find or load main class" error. If I try to run the class from the terminal by running
javac <filename.java>
java <filename>
it works. I tried to do "rebuild project" and to make a new project and it did not change anything.
Here is a photo of my project:
Here is a photo of my Run-Edit configurations
CodePudding user response:
Your java code needs to be placed in src/main/java directory instead of src/main/kotlin.
Kotlin compiler doesn't compile Java files in Kotlin source roots, Java compiler doesn't compile Java files in Kotlin source roots, therefore '.class' files are not created by any of the compilers and you get this error.
The solution is to move *.java files into src/main/java directory. Create this directory manually if it doesn't exist.


