File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception in thread "main" java." Watch "Exception in thread "main" java." New topic
Author

Exception in thread "main" java.

Eddie Jones
Greenhorn

Joined: Jan 28, 2003
Posts: 7
Hi Y'All
If ther eis anyone who can help me, it's here.
I am new to Java and trying it to get the feel of writing programings, but my first problem that has stumped me is the NoClassDefFoundError. I thimk it maybey in the install, I set the path to "c:\windows;c:\windows\command;c:\ibmtools;c:\j2sdk1.4.1_01\bin",
the set the classpath to "set classpath=.;c:\j2sdk1.4.1_01\lib\tools.jar", it will complie the program "Factorial.java", but when I try to run it that's when it says it can't find the class. What if any can I do to find out what I did wrong, all help would be apperciated
Greg Brouelette
Ranch Hand

Joined: Jan 23, 2002
Posts: 144
NoClassDefFoundError is almost always a classpath issue. You'll need to look at few things.
1. What directory are the class files in? Is that directory in your classpath?
2. If not then you have a dot at the beginning of your classpath. Are you running "java Factorial" from the directory where your class files exists?
3. Make sure your command line for running the program is
java Factorial
and NOT
java Factorial.class
You don't need the ".class" on the file name when running the program.
Hope it helps


For a good Prime, call:<br />29819592777931214269172453467810429868925511217482600306406141434158089
Eddie Jones
Greenhorn

Joined: Jan 28, 2003
Posts: 7
I have tried all I can find on what to do about the "NoClassDefFounedError" in the pject that I wrote and have set the classpath everyway I could and still can't get it to run, the program I wrote is"

and I still get the sane error. Can anyone sugest what is wrong?
[ February 07, 2003: Message edited by: Marilyn de Queiroz ]
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Originally posted by Eddie Jones:
int put = Integer.parseInt(args[0]); // Gets user's input
double result = factorial(input); //

I think you are getting an error when your compile your class, am I right?
Try change 'double result = factorial(input)' to: 'double result = factorial(put)'
Rene


Regards, Rene Larsen
Dropbox Invite
Eddie Jones
Greenhorn

Joined: Jan 28, 2003
Posts: 7
I changed the " int input = Integer.parseInt(args[0]);" for the error "int put = Integer.pardeInt{args[0]) and now it complies but when I run the program from DOS Command I still get the same error message. What is it that I don't see?
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Are you sure that you run the program like e.g.: "java Factorial 4" from the directory where the .class file is?
Rene
Eddie Jones
Greenhorn

Joined: Jan 28, 2003
Posts: 7
What I do is open MS DOS and type cd\ to get into the C:\> DIR where it sits in the C Dir then I type " java Factorial 4" to see if the program will execute and I still get the "NoClassDefFoundError" prompt. I used TextWord as the editor to complie it and there are no errors found when it complies but when I run it from the editor I get an array error but I know because it has no input is the reason I get it. But when I run it through DOS is when I get the error. I am still confused as to what it is. Any ideas?
Gopi Balaji
Ranch Hand

Joined: Jan 23, 2003
Posts: 84
Originally posted by Eddie Jones:
Hi Y'All
..
the set the classpath to "set classpath=.;c:\j2sdk1.4.1_01\lib\tools.jar", ..

Try after changing this to
Set CLASSPATH=.;C:\j2sdk1.4.1_01\jre\lib\rt.jar
-GB.
Eddie Jones
Greenhorn

Joined: Jan 28, 2003
Posts: 7
I am stil at stumped
as to what is wrong with the "Exception to thread main()" error I keep getting. I found a file called "classes" in a java folder located in my windows folder on my C drive but I stored my Jsdk1.4 jre is in my program file on My C drive. I am unsure what I had done. I am using 98 se OS and I see java folders all over my C diver and I just can't figure out what's wrong.If I had to reset my Java J2sdk will someone walk me through it please.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
path=c:\windows;c:\windows\command;c:\ibmtools;c:\j2sdk1.4.1_01\bin

This looks ok.

When you type
javac Factorial.java
you get the C: prompt back, right? You don't get an error like
C:\>javac Factorial.java
error: cannot read: Factorial.java
1 error

right?

By the way, what is the subdirectory where you have your source file (Factorial.java) ?

classpath=.;c:\j2sdk1.4.1_01\lib\tools.jar

This should be
classpath=C:\j2sdk1.4\lib;.;C:\JAVA (if your source file (Factorial.java) is in C:\JAVA .

cd C:\JAVA
javac Factorial.java
(at this point you should be able to see a file named Factorial.class in the same subdir where Factorial.java is located.)
java Factorial
[ February 07, 2003: Message edited by: Marilyn de Queiroz ]

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
I found a file called "classes" in a java folder located in my windows folder on my C drive

Don't touch that file. Windows needs it.

One more question: Are you setting your classpath in your autoexec.bat file?
Eddie Jones
Greenhorn

Joined: Jan 28, 2003
Posts: 7
I made the change in my "set CLASSPATH=" and the subdirectory where the code sits is "C:\Mydocs" how am I to set the command line in DOS to find it?
Eddie Jones
Greenhorn

Joined: Jan 28, 2003
Posts: 7
Oh yeah, when I try to complie in MSDOS "C:\WINDOWS>" I get the error " bad comand or file name" but when I complie MSDOS "C:\>" I do get the "ERROR: Cannot read" promt,as before I asked do I need to point the command to "C:>\MyDocuments\"?
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
So now you have a statement in your autoexec.bat that looks like:

set CLASSPATH=C:\j2sdk1.4\lib;.;C:\Mydocs
You should compile in C:\Mydocs>
The easiest way is to
cd \
cd Mydocs

Now compile using
javac Factorial.java

Do you see the Factorial.class file?

Now, while you are still in C:\Mydocs>, run your program using:
java Factorial

Be sure that you are capitalizing properly and that you are not using
java Factorial.class
C:\MyDocuments\> is irrelevant to this discussion.
[ February 07, 2003: Message edited by: Marilyn de Queiroz ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception in thread "main" java.