How do I fix "class file contains wrong class"?
<p>I'm using IntelliJ IDEA and JDK 8.</p>

<p>I have some compiled Java Classes, and I imported them as an external library, as the code I have uses methods inside those classes. However, I can't seem to make actually use those .class files.</p>

<p>Whenever I try to run this code:</p>

<pre><code>public static int spendOnCokes(int sum, DrinksMachineA mach) {
    int count = 0;
    mach.insert(sum);

    try {
        while (mach.getBalance() &gt;= mach.getPrice()) {
            mach.pressCoke();
            count++;
        }
    } catch (EmptyMachineException e) {
    }
</code></pre>

<p>It gives me the following error:</p>

<pre><code>    Error:(21, 45) java: cannot access com.sanac.DrinksMachineA
  bad class file: /homes/jmcv3/Documents/Java/ClassesArchive/com/sanac/DrinksMachineA.class
    class file contains wrong class: DrinksMachineA
    Please remove or make sure it appears in the correct subdirectory of the classpath.
</code></pre>

<p>I've searched around, and some people seemed to suggest that it had something to do with the folder hierarchy/package name. It looks fine to me though. I also tried switching to JDK 5 as that's what the .class file was compiled with, to no avail. (Also read that somewhere.)</p>

<p>Here's a screenshot outlining the directory structure:</p>

<p><a href="https://i.stack.imgur.com/mnOlA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mnOlA.png" alt="Structure"></a></p>

<p>All I want is to be able to use those compiled .class files with my code. Seems to be so simple, so I must be missing something really stupid. Any ideas?</p>