title: bad class file using javac
body: <p>Some background: I'm a student just learning Java, and usually the professor handles making sure our assignments have the right class path. However, the whole semester I've been plagued by the same problem, and I still don't understand what's going wrong.</p>
  
  <p>As an example, I have two files, <strong>MyProgram.java</strong> located in the folder "MyProject" and <strong>MyProgramTest.java</strong> located in the folder "ClassProject", which also contains "MyProject". <code>MyProgramTest</code> creates a <code>MyProgram</code> object and lets you test its functionality. </p>
  
  <p><code>MyProgramTest</code> has the line <code>import MyProject.MyProgram;</code> The compiling instructions my instructor gives is to use <code>javac MyProject/*.java</code> while in "ClassProject" which works fine. Then, we are to use <code>javac MyProgramTest.java</code> in the same directory. However, the compiler claims:</p>
  
  <pre><code>import MyProject.MyProgram;
  
  bad class file: .\MyProject\MyProgram.class
  
  class file contains wrong class: MyProgram
  
  Please remove or make sure it appears in the correct subdirectory of the classpath.
  </code></pre>
  
  <p>So I don't quite understand why this is happening. <strong>MyProgram</strong> is in the <strong>MyProject</strong> directory, and that directory is in the folder I'm in. Since the instructor uses this exact method to compile these programs, I keep getting screwed since mine never compile correctly. Any idea what I'm doing wrong, or how I can fix the file to compile this way without changing the structure of the directories?</p>