1

I'm getting this error in the run window when I click run in IntelliJ with my program.

Exception in thread "main" java.lang.ClassNotFoundException: PackageNameInMyProject.src.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:122)

Process finished with exit code 1

The above message pops up briefly before popping over the the messages window and showing me this:

Information:Using javac 1.8.0_74 to compile java sources

Information:java: Errors occurred while compiling module 'MyProjectName'

Information:6/16/16, 2:31 AM - Compilation completed with 2 errors and 0 warnings in 438ms

Error:java: /production/MyProjectName: does not exist

/path/to/stuff/MyProjectName/PackageName/.idea/vcs.xml

Error:resources: /production/MyProjectName/PackageName/.idea/vcs.xml (No such file or directory)

I tried googling the error I'm getting, and I didn't find anything that even mentions the production directory listed above. My only clue as to what this is is something for deploying testing vs production code, and I am inexperienced with IntelliJ's inner workings so I don't know how to properly adjust those settings or how this has even come into play when running a basic program.

Here is my project package layout

Something that is perhaps unique to my setup is that I am trying to run code from a src directory that's inside a package that's inside a project. Although I have removed that variable and put the src directory directly in the project directory and I still get the same errors.

I couldn't turn up anything besides this similar question, however that question doesn't touch on the production folder aspect (which I'll eventually need to know about as well). This question is answered, but not in terms of IntelliJ, so it doesn't help. Helpful answers include thought processes about how to troubleshoot these sort of problems and even how to do an internet search for what the problem is from the information I have.

Community
  • 1
  • 1
OKGimmeMoney
  • 575
  • 2
  • 7
  • 19
  • Is/are your source root(s) configured correctly? – vikingsteve Jun 16 '16 at 08:12
  • Under FIle > Project Structure > Modules > Source Tab my project's folder is added as a content root. To double check I clicked "Add content root" and chose the same directory and it said it already existed in my list. Is there something more I should do here or move on to a different step? – OKGimmeMoney Jun 16 '16 at 08:28
  • is it a maven project? – JimHawkins Jun 16 '16 at 08:49
  • Bare with me here, I'm unsure what is entailed by a project being a "maven project" I know that there is supposed to be at least a structure to the packages, but I am not sure what the structure is supposed to be. I have never had issues with creating packages inside packages before though (if that helps at all). How do I check if it's a maven project? – OKGimmeMoney Jun 16 '16 at 08:59
  • I guess it's not a maven project... can you make a little screenshot from the Project View? With packages unfolded – JimHawkins Jun 16 '16 at 09:40
  • Ok, I added it to the OP. Do you think the production error line means anything meaningful here? – OKGimmeMoney Jun 16 '16 at 09:59
  • I guess there is a mistake in the package declaration in your Java source. Show it please. And the structure looks very strange – JimHawkins Jun 16 '16 at 10:51
  • All of the java files have at the top "package PackageName.src". The structure was made that way to have two closely related programs in the same projects but different packages, then when I'm ready they're going to use each other's files. – OKGimmeMoney Jun 16 '16 at 11:41

2 Answers2

2

The problem is that you have specified the project's top folder .../production/MyProjectName as your "source" directory. You need to and unset the .../production/MyProjectName as your source directory and then specify the src directory .../production/MyProjectName/PackageName/src as your source directory in File > Project Structure > Modules > Source Tab.

JetBrains has a nice help document here on how to set up a basic project.

As others have mentioned, once things get beyond using just java.* libraries, many people use Maven for project set up and dependency management which integrates nicely with Intellij.

Kirby
  • 15,127
  • 10
  • 89
  • 104
1

src is the name of the source directory in a project in some IDEs (i.e. eclipse, IntelliJ) and build tools (i.e. maven). So it looks strange when someone uses src as a package name. Edit: You shouldn't use src as the name of the top level package (i.e. src.model.entitities), but I think it's OK to use it in a deeper level (i.e. com.powerdata.model.src).

Code is written once, but it is read very multiple times. So you, as a developer, should strive for clearness.

I suggest you rearrange your directory structure:

directorie in explorer enter image description here

JimHawkins
  • 4,843
  • 8
  • 35
  • 55