Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / May 2004

Tip: Looking for answers? Try searching our database.

Java newbie can't "Hello world" on Windows

Thread view: 
Richard Anderson - 18 May 2004 17:25 GMT
I typed in the first example program from Java in a Nutshell and
installed the Java SDK from Sun's website on my WinXP system.  The
code complies cleanly, but when I run it I get:

C:\home\java> java Factorial.class 4
Exception in thread "main" java.lang.NoClassDefFoundError:
Factorial/class

It looks to me like the code clearly defines the class.  Do I need to
put the files in a particular location?  I've got the .java and .class
file in my current working directory.

Factorial.java:

public class Factorial {
 public static void main(String[] args) {
   int input = Integer.parseInt(args[0]);
   double result = factorial(input);
   System.out.println(result);
 }

 public static double factorial(int x) {
   if (x < 0)
     return 0.0;
   double fact = 0.0;
   while (x > 1) {
     fact = fact * x;
     x = x - 1;
   }
   return fact;
 }
}

Here's the Java version info:
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)

Richard Anderson
John - 18 May 2004 17:27 GMT
> I typed in the first example program from Java in a Nutshell and
> installed the Java SDK from Sun's website on my WinXP system.  The
[quoted text clipped - 3 lines]
> Exception in thread "main" java.lang.NoClassDefFoundError:
> Factorial/class

try this:

C:\home\java> java Factorial 4
Andrew Thompson - 18 May 2004 17:59 GMT
> try this:
>
> C:\home\java> java Factorial 4

That will work if the current directory
is part of the classpath, otherwise, this
can add the current directory.

C:\home\java> java -cp . Factorial 4

Signature

Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

Roedy Green - 19 May 2004 00:26 GMT
>NoClassDefFoundError

see http://mindprod.com/jgloss/gettingstarted.html
http://mindprod.com/jgloss/helloworld.html
http://mindprod.com/jgloss/errormessages.html#NOCLASSDEFFOUNDERROR
http://mindprod.com/jgloss/classpath.html

Signature

Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.