Reputation: 882
I can't get this to work!
I found lots of those problems on stackoverflow but 90% of the problems were related to the missing package name, but I don't have any package, it's "unnamed" therefore must not be defined within forName()
parameter.
A class that is not in a named package is in an unnamed package. Thus the full class name is "Main". Such classes cannot be used from a named package, except via reflection.
The other solution was specifying classpath, however src (blue folder) IS a classpath as said here
You can right click on any directory in your IntelliJ project, select "Mark Directory As...", and choose "Source Root". That director folder will change color from yellow to blue; IntelliJ considers all those directories to be in your CLASSPATH.
Yet it's still not working! It slowly drives me nuts.
Upvotes: 0
Views: 146
Reputation: 4262
This message means that you need to handle the checked exception, that is, java.lang.ClassNotFoundException
. It doesn't mean you couldn't find/load this class.
In order to handle checked exception, you can
try {...} catch (ClassNotFoundException ex) {...}
.main
method: main(String[] args) throws ClassNotFoundException
.In IDEA, you can always use alt + enter to see suggestions.
Upvotes: 2