• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Maybe it's me.

 
Patrick Roberts
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I'm new here, and am trying to learn Java as my first programming language. using Head First Java 2nd Edition. Unfortunately I think I hit my head before studying. There is something I'm not getting. I'm not even sure if I'm supposed to be compiling and trying to run these codes yet. But my first one is the simple Doobee program. I have managed to get it to compile. But then I get an error when I try to run it.

Here is my code



Then here is the message I get after I compile it and try to run it

java Doobee
Exception in thread "main" java.lang.NoClassDefFoundError: Doobee
Caused by: java.lang.ClassNotFoundException: Doobee
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
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: Doobee. Program will exit.

I've compared my code to the book, and others. I can't find anything wrong. I'm wondering if I'm even supposed to be attempting to compile and run them at this point. Thanks for any help!
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Patrick!

The error you're getting is a very common (perhaps the most common) error that beginners get. NoClassDefFoundError means that Java cannot find the class you're trying to run.

In your case, this most likely happens because your class is named DooBee, but on the command line you're calling it Doobee. Java is case-sensitive; according to Java, DooBee is not the same as Doobee. Try running it like this:

java DooBee

Other reasons why you could get this error is when your classpath is not set correctly. The classpath specifies where Java searches for *.class files. If you don't specify it, Java will by default look in the current directory for *.class files.
 
Patrick Roberts
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much! I'm just going to outlaw capital letters I think... Now I just have to figure out that 99 bottles of beer.

And I just got that one to work woo!
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am afraid you can't outlaw capital letters; they are a standard part of Java™ naming styles.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic