Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

same error when using XP and Eclipse to run program

 
Derek B Smith
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I am using Eclipse IDE to practice Java 5 coding as well as the DOS command line. I am referencing HeadFirst Java for practice and the code error I cannot fix is this from the command line and from within Eclipse IDE:
Any help please?

thank you
derek


From Eclipse:
java.lang.NoClassDefFoundError: DooBee
Exception in thread "main"

From DOS:
C:\temp>javac DooBee.java

C:\temp>java DooBee
Exception in thread "main" java.lang.NoClassDefFoundError: DooBee

Here is my test code:

public class DooBee {
public static void main (String[] args) {
int x = 1;
while (x < 3) {
System.out.print("Doo");
System.out.print("Bee");
x += 1;
}

if (x == 3) {
System.out.print("Do");
} // end if
} // end main
} // end class

Here are my ENV variable:

C:\temp>echo %PATH%
C:\Perl\bin\;C:\ClarifyCRM12.0\Configurator\Common Files\CCAutomation;C:\ClarifyCRM12.0\Clarif
yClient;C:\Program Files\Compaq\Compaq Management Agents\Dmi\Win32\bin;C:\WINDOWS\system32;C:\
WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\IBM\Client Access;C:\Program Files\IBM\Clien
t Access\Shared;C:\Program Files\IBM\Client Access\Emulator;C:\Program Files\ShowCase STRATEGY
\bin;C:\WINDOWS\system32\nls;C:\WINDOWS\system32\nls\ENGLISH;C:\MSSQL7\BINN;C:\Program Files\M
icrosoft SQL Server\80\Tools\BINN;c:\progra~1\VIAVOI~1;C:\Sun\AppServer\jdk\bin\;C:\Sun\AppSer
ver\bin;C:\Program Files\websm\bin;C:\eclipse;C\Perl\bin;

C:\temp>echo %CLASSPATH%
C:\Sun\AppServer\jdk\lib;C:\Sun\AppServer\jdk\jre\lib

C:\temp>echo %JRE_LIB%
C:\Sun\AppServer\jdk\jre\lib
 
fred rosenberger
lowercase baba
Bartender
Posts: 12122
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm assuming you're getting a class file. from the directory where that class file is (probably you're c:/temp), do this:

java -cp . DooBee
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15272
37
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C:\temp>echo %CLASSPATH%
C:\Sun\AppServer\jdk\lib;C:\Sun\AppServer\jdk\jre\lib


You don't have the current directory (".") in your classpath. When you try to run a Java program from the command line, Java will search for class files in the directories and JAR files that are in your classpath.

Add the current directory to your classpath:

set CLASSPATH=C:\Sun\AppServer\jdk\lib;C:\Sun\AppServer\jdk\jre\lib;.

Notice the ";." at the end.

(Note: If the CLASSPATH environment variable is not set at all, Java will look in the current directory by default).

You can also use the "-cp" (or "-classpath") option as Fred suggests, to set the classpath on the command line explicitly.
[ October 09, 2006: Message edited by: Jesper Young ]
 
Derek B Smith
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that was it...thanks guys!

derek
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic