SteelToe
SteelToe

Reputation: 2597

Error "class not found" in IntelliJ ide on mac

I am currently running the latest IntelliJ on mac os el capitan.

I have built a project and it builds successfully, however when I try to run it I get the following message:

    Exception in thread "main" java.lang.ClassNotFoundException: com.company.Main
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:123)

 Process finished with exit code 1

I have looked at this question Error "ClassNotFoundException" in IntelliJ IDEA however none of the answers there worked.

Any Ideas?

Upvotes: 1

Views: 1204

Answers (1)

Mike Nakis
Mike Nakis

Reputation: 62110

You might not know it, but when you run your program from within IntelliJ IDEA, you are making use of a Run/Debug Configuration to do that. IntelliJ IDEA keeps important information about how to run your program in these Run/Debug Configurations. If your program does not start, it is most likely due to a Run/Debug Configuration misconfiguration.

Edit your Run/Debug Configurations, find the Run/Debug Configuration that you are currently using, and look at the "Main class:" field. You will find that it is "com.company.SomeClass". Replace that with the full name of your main class. Your main class is the class with your main() function.

Alternatively, find the class that contains your main() function, open up a context menu on that class, and select 'Run' or 'Debug'. This will create a new Run/Debug configuration for it.

If the newly created Run/Debug configuration is not working, open up the Run/Debug Configuration Dialog and compare your newly created Run/Debug configuration against the old one, there may be some additional setting that needs to be copied from the old to the new.

The Run/Debug Configuration Dialog can be found by selecting "Edit configurations..." from the Run/Debug Configuration Drop Down List.

The Run/Debug Configuration Drop Down List can be found on the main toolbar of IntelliJ IDEA. (Normally, it is the only drop-down list on the toolbar.)

Upvotes: 2

Related Questions