0

After extensive research through Google, Stackoverflow and peers I am still unable to solve the below stated issue.

IntelliJ is unable to locate any main class of whatever file I choose:

Error: Could not find or load main class nl.sam.inventory.InventoryApplication

I have followed the answer which was posted on SO: Error "ClassNotFoundException" in IntelliJ IDEA

My main class:

package nl.sam.inventory;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class InventoryApplication {

    public static void main(String[] args) {
        SpringApplication.run(InventoryApplication.class, args);
    }
}

My run settings are left as default (IntelliJ picked these up).

My project structure: Project Structure

If I left anything out please state so.

I have verified I have a JRE (11) and JDK (11) installed and working on my machine. In a terminal the program runs just fine: in IntelliJ I get the aforementioned error.

Edit: I use Maven for project management. A project without maven shows the same behaviour.

Sam
  • 15
  • 7
  • possible dublicate: https://stackoverflow.com/questions/10654120/error-could-not-find-or-load-main-class-in-intellij-ide – Mustafa Çil Dec 12 '19 at 11:30
  • This means that your project wasn't successfully imported into IntelliJ or it wasn't rebuild before you attempted to run. – Karol Dowbecki Dec 12 '19 at 11:31
  • @MustafaÇil I have tried the answers of that question too: no result. – Sam Dec 12 '19 at 11:31
  • @KarolDowbecki the project was created through IntelliJ. After a rebuild it still does the same. – Sam Dec 12 '19 at 11:32
  • Created or imported? If you are using external build tool like Maven you are suppose to import, not create new project from scratch. – Karol Dowbecki Dec 12 '19 at 11:33
  • Check build path. Make sure the package is there in the build path of the project settings.. Or try this https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000156824-How-to-choose-main-class – A_01 Dec 12 '19 at 11:34
  • @KarolDowbecki1 I used the "Create project" from the splash screen of IntelliJ. It created the project for me. I also tried a console application through the template given by IntelliJ with the same result. – Sam Dec 12 '19 at 11:35
  • @A_01 I have tried the answers given in your link. It didn't work unfortunately – Sam Dec 12 '19 at 11:38
  • Are you using Maven to define your project? – Karol Dowbecki Dec 12 '19 at 11:40
  • Please specify your build type. It is maven, it is gradle, or? – Antal Attila Dec 12 '19 at 11:41
  • I'm using the default options given by IntelliJ. It's through Maven, yes. – Sam Dec 12 '19 at 11:42
  • Most likely your source file exists outside of a designated source directory. – jwenting Dec 12 '19 at 11:51
  • I have seen this answer in a different question: I can verify that this is not the case. The file exists in the src/ folder. – Sam Dec 12 '19 at 11:52
  • There could be many reasons for this error, see https://stackoverflow.com/a/42660624/104891 for some. If the issue persists, please submit a ticket at https://intellij-support.jetbrains.com/hc/requests/new with the [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) and [idea.log](https://intellij-support.jetbrains.com/hc/articles/207241085) attached. – CrazyCoder Dec 12 '19 at 12:13

1 Answers1

0

This issue was caused by something not yet described before. My path had a space in it, which my MacBook turned into a :. Due to this the main class could never be found. I've changed my username to not contain a space, and it now works just fine.

Sam
  • 15
  • 7