1

I'm writing a program in Eclipse, and running it from the command line. In an earlier version of the program, it took no arguements, and I could run it fine as > java foo. I've since added a couple of arguments, and need to run it as > java foo file1.txt file2.txt. When I run this, I get a java.lang.NoClassDefFoundError: error. Even when I include the classpath, i.e. > java foo file1.txt file2.txt -cp . it still doesn't work.

Could someone point me in the right direction?

EDIT Here is the complete stack trace

Exception in thread "main" java.lang.NoClassDefFoundError: edu/cuny/pausePred/TemplateToCharTestVector (wrong name: edu/cuny/pausepred/TemplateToCharTestVector)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:480)
4
  • 1
    Include the stack-trace for the exception; it will give the name of the class it was looking for. Most likely you need to give the fully-qualified name. And the classpath needs to be before the class name or else it's treated as a parameter to the program. Commented Jan 10, 2013 at 17:38
  • @DelShekasteh - Yes, I did Commented Jan 10, 2013 at 17:45
  • @SoftwareMonkey - I just added the stack trace. Could you point me to where I should look? Commented Jan 10, 2013 at 17:48
  • It cannot load edu.cuny.pausePred.TemplateToCharTestVector, which is a class which foo uses. Commented Jan 10, 2013 at 18:57

3 Answers 3

1
  • Write the full directory path then compile all classes
  • Write the full directory and run the class that contains the main() method
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the idea. Unfortunately, I'm now getting the error Could not find or load main class [full directory path]. Any suggestions?
Run the class that contains the main() method. When compiling a file named 'BankAccounts'... compile like this: <file directory> BankAccounts.java then run like this: <file directory> BankAccounts
Take notice of my revised answer.
Post what you're typing exactly & the error you're currently getting in command line.
1

A common mistake for beginners in using Java is misunderstanding class names and the classpath.

A class name is a fully qualified thing which includes the package; the compiler lets you refer to a class using its base name, which is a convenience to keep programming sane. The actual name of your class is <package>.foo.

The classpath must include the root of any packages which you are using. So if your package for foo is edu.cuny.pausePred then the class name for foo is edu.cuny.pausePred.foo and the classpath must include the directory which contains edu, not the directory which contains foo.

You command line should be something like:

jave -cp the-directory-root-for-java-sources foo file1.txt file2.txt

noting that this assumes that the two data files are in the current directory.

As an aside, note that a class base name should be lead uppercase, so Foo, not foo.

Comments

1
Exception in thread "main" java.lang.NoClassDefFoundError: 
  edu/cuny/pausePred/TemplateToCharTestVector 
  (wrong name: edu/cuny/pausepred/TemplateToCharTestVector)

Paths in java are case-sensitive. pausepred is not the same as pausePred

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.