Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception in thread "main" java.

 
Eddie Jones
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Eddie Jones
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Eddie Jones
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic