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
Exception in thread "main" java.lang.NoClassDefFoundError: Doobee
Caused by: java.lang.ClassNotFoundException: Doobee
at java.security.AccessController.doPrivileged(Native Method)
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!
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:
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.