title: How to resolve a NoClassDefFoundError when working with class files
body: <p>I am still trying to learn Java and decided to take it 1 step further and attempt to use external class files to store data structures (like the header files in C). I keep running into NoClassDefFoundError and would like some methods or techniques that can show me what is going wrong (and where) as the message is not very clear to me :(</p>
  
  <p>I have my directory structure set up as follows:</p>
  
  <pre><code>tarskin@5-PARA-11-0120:~/programming/Java/FindGlycopeps$ ls
  Default.mzML  FindGlycopeps.class  FindGlycopeps.java  glycoproteomics
  tarskin@5-PARA-11-0120:~/programming/Java/FindGlycopeps$ ls glycoproteomics/
  Spectrum.class  Spectrum.java
  </code></pre>
  
  <p>The 'main' program is coded as follows:</p>
  
  <pre><code>package glycoproteomics;
  import java.util.*;
  import java.util.regex.*;
  import java.io.*;
  import java.lang.*;
  
  public class FindGlycopeps {
  
  public static LinkedList outside_tag_reader (String filename, String tag) {
          LinkedList&lt;String&gt; someList = new LinkedList&lt;String&gt;();
          DataInputStream in = null;
      try {
          FileInputStream input = new FileInputStream(filename);
          in = new DataInputStream(input);
          BufferedReader reader = new BufferedReader(new InputStreamReader(in));
          String line;
          String regexp = "&lt;"+tag+"&gt;(.*)&lt;/"+tag+"&gt;";
          Pattern pattern = Pattern.compile(regexp);
          while ((line = reader.readLine()) != null) {
              Matcher matcher = pattern.matcher(line);
              if (matcher.find()) {
                  String buffer = matcher.group(1);
                  someList.add(buffer);
              }
          }
          in.close();
      } catch (Exception x) {
          System.err.println(x);
      }
      return(someList);
  }
  
  public static void main (String [ ] args) {
      LinkedList&lt;String&gt; binary = new LinkedList&lt;String&gt;();
      ArrayList&lt;Spectrum&gt; spectra = new ArrayList&lt;Spectrum&gt;();
      String file = args[0];
      if (file != null) {
          binary = FindGlycopeps.outside_tag_reader(file,"binary");
          int j = 0;
          for (int i = 0; i &lt; binary.size(); i++) {
              String buffer = binary.get(i);
              if (i % 2 == 0) {
                  spectra.add(j, new Spectrum());
                  spectra.get(j).mzList.add(buffer);
              } else {
                  spectra.get(j).intList.add(buffer);
              }
              j++;
          }
          System.out.println(spectra.get(1).mzList); // purely for testing
  
          } else {
              System.out.println("No file was specified");
          }
      }
  }
  </code></pre>
  
  <p>The 'Data structure' is coded as follows:</p>
  
  <pre><code>package glycoproteomics;
  import java.util.ArrayList;
  
  public class Spectrum implements Comparable&lt;Spectrum&gt;{
     float precursor;
     ArrayList&lt;String&gt; mzList;
     ArrayList&lt;String&gt; intList;
  
     public int compareTo(Spectrum arg0) {
        return 0;
     }
  }
  </code></pre>
  
  <p>I have compiled both .java files with just javac  and been attemping to run the main class, from the 'root' using several variations of java -classpath (also tried -cp) ./://Java/FindGlycopeps/glycoproteomics FindGlycopeps and it keeps giving errors such as:</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: FindGlycopeps (wrong name: glycoproteomics/FindGlycopeps)
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
      at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
  Could not find the main class: FindGlycopeps. Program will exit.
  </code></pre>
  
  <p>What would be good ways to figure out how it is going wrong and what should be changed in my 'thinking'? I would appreciate an explanation why something should be done instead of 'do this to fix it' if possible.</p>
  
  <p>Thanks in advance</p>