Overview
How to solve IntelliJ - Error: Could not find or load main class
This problem happens to me frequently, then I did a lot of research. Eventually, I find out the way to solve it. The problem is that when I look at the configurations, I cannot find the src folder in it nor choose my main class from the list neither.
![](https://www.jakezhong.com/assets/Screen-Shot-2019-10-02-at-10.40.27-PM.png)
![](https://www.jakezhong.com/assets/Screen-Shot-2019-10-02-at-10.38.51-PM-1024x179.png)
In summary, you need to:
- Mark your src directory as “Sources Root”
- Cancel your src’s exclusion
- Delete your .idea folder and re-add your module in “Project Structure”. After this, try 1, 2 again
- Rebuild your project, or delete your current build and add a new one
If you don’t know how to do so, I will explain them in detail, just keep reading.
First attempt: here, we can mark our src folder as one of the “Sources Root”, which you can do by right click on the src folder on your file tree.
![](https://www.jakezhong.com/assets/Screen-Shot-2019-10-02-at-10.43.18-PM-869x1024.png)
Second Attempt: if the “Sources Root” doesn’t work for you, you still can try to “Cancel Exclusion” from the same option here:
![](https://www.jakezhong.com/assets/Screen-Shot-2019-10-02-at-10.46.39-PM-870x1024.png)
Third Attempt: if both solutions above cannot help you, then I think you are having the same issue as me, which took me a while to figure it out. Now you can try to delete your .idea folder and then add a new module in the “Project Structure” if they are gone and re-try 1, 2 again. IMPORTANT: make sure you back up all your project files before this action.
![](https://www.jakezhong.com/assets/Screen-Shot-2019-10-03-at-3.30.08-PM.png)
![](https://www.jakezhong.com/assets/Screen-Shot-2019-10-03-at-3.30.47-PM-1024x637.png)
Last but not least: This is optional, in case it still doesn’t work here – afterward, also try to rebuild your project, which you can do from the Build option on top, or you can delete your current build and add a new one. A quick way, you can delete your build and then just run the main method, the IDE may automatically configure for you. This solution works well for me, so I guess it will do the same job for you too.
![](https://www.jakezhong.com/assets/Screen-Shot-2019-10-02-at-10.59.12-PM.png)
That’s it, I hope my solution helps you to fix this problem.