Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > ClassDefNotFound Exception

Reply
Thread Tools

ClassDefNotFound Exception

 
 
Steve Burrus
Guest
Posts: n/a
 
      05-27-2004
I am wondering just why i seem to get the old Java "ClassDefNotFound
Exception" so much when I either try to compile or execute a Java source
code file when I KNOW that I have everything about the Java installation
properly installed and configured!!!

 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      05-27-2004
On Thu, 27 May 2004 04:28:09 GMT, Steve Burrus <(E-Mail Removed)>
wrote or quoted :

>I am wondering just why i seem to get the old Java "ClassDefNotFound
>Exception" so much when I either try to compile or execute a Java source
>code file when I KNOW that I have everything about the Java installation
>properly installed and configured!!!


see http://mindprod.com/jgloss/errormess...SDEFFOUNDERROR
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      05-27-2004
On Thu, 27 May 2004 04:28:09 GMT, Steve Burrus wrote:
> I am wondering just why i seem to get the old Java "ClassDefNotFound
> Exception" so much when I either try to compile or execute a Java
> source code file when I KNOW that I have everything about the Java
> installation properly installed and configured!!!


Here's a good rule of thumb: When you KNOW that you're doing
everything correctly but it still doesn't work, then something you
know might very well be WRONG.

Of course there are extremly few clues in your post to give the
slightest indication of what you might be doing wrong. Are you asking
us to guess why it doesn't work?

Have a look here for some clues:

http://www.catb.org/~esr/faqs/smart-questions.html
http://www.physci.org/codes/sscce.jsp
http://www.yoda.arachsys.com/java/packages.html

Here are two issues with your problem description that may be related
to the problem itself:

- are you really trying to execute a *source* code file?
- do you really get ClassDefNotFoundException when you *compile*?

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
Steve Burrus
Guest
Posts: n/a
 
      05-27-2004
Gordon Beaton wrote:

Of course there are extremly few clues in your post to give the
slightest indication of what you might be doing wrong. Are you asking
us to guess why it doesn't work?

Okay Gordon, to both respond back to your apparent need to know some
details about this exception, AND to maybe "re-activate" this particular
thread which, I noticed, hasn't seen much activity on since early this
AM, here is a "PortScanner.java" file which has given me the exception
when i try to execute it, i.e., use the java interpreter on it, not
necessarily when I try to compile it, which it does okay.

"import java.io.*;
import java.net.*;

/**
* Port Scanner
*
* Scans for servers listening on a range of ports.
*/
public class PortScanner
{
final static int LOW_RANGE = 0; //scan reserved ports
final static int HIGH_RANGE = 1023;

public static void main(String[] args)
{
Socket connect=null;
String host = "localhost"; //defaults to local host

if (args.length > 0)
{
host = args[0]; //sets host to command-line parameter
}
for (int iCount = LOW_RANGE; iCount < HIGH_RANGE; iCount++)
{
System.out.print("Checking port " + iCount + "...");
try
{
connect = new Socket(host, iCount);
System.out.println("Server responding on port " +
iCount + " of " + host);
}
catch (UnknownHostException e)
{
System.err.println("Host is invalid.");
break;
}
catch (IOException e)
{
System.out.println("No server found");
}
finally
{
try
{
connect.close(); //close socket connection
}
catch (Exception e) {}
}
}
}
}"


 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      05-28-2004
On Thu, 27 May 2004 20:45:59 GMT, Steve Burrus wrote:
> Okay Gordon, to both respond back to your apparent need to know some
> details about this exception, AND to maybe "re-activate" this
> particular thread which, I noticed, hasn't seen much activity on
> since early this AM, here is a "PortScanner.java" file which has
> given me the exception when i try to execute it, i.e., use the java
> interpreter on it, not necessarily when I try to compile it, which
> it does okay.


Well, your code works fine for me.

Probably you are doing something wrong. Show us the command line you
use run the program, and exactly what the error message looks like.

Try this from the directory containing PortScanner.class:

java -cp . PortScanner

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
Steve Burrus
Guest
Posts: n/a
 
      05-28-2004
Gordon Beaton wrote:
Well, your code works fine for me.
>
> Probably you are doing something wrong. Show us the command line you
> use run the program, and exactly what the error message looks like.
>
> Try this from the directory containing PortScanner.class:
>
> java -cp . PortScanner


"Success" Gordon is what I can say I achieved with your solution which u
offered to me, so thanx for that!! BTW : what is that -cp interpreter
switch that got it going for me in DOS??? And also, just generally, what
should I do the next time that I might encounter that ClassDefNotFound
exception either trying to compile or run a java file?


 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      05-28-2004
On Fri, 28 May 2004 06:00:09 GMT, Steve Burrus wrote:
> "Success" Gordon is what I can say I achieved with your solution
> which u offered to me, so thanx for that!! BTW : what is that -cp
> interpreter switch that got it going for me in DOS???


It adds the current directory to the classpath so the JVM can find
your class. It's in the documentation, which I suggest you have a look
at:

http://java.sun.com/j2se/1.4.2/docs/...dows/java.html

> And also, just generally, what should I do the next time that I
> might encounter that ClassDefNotFound exception either trying to
> compile or run a java file?


Add the relevant directories to your classpath.

Also have a look at the following link, which I posted in my first
reply. It will come in handy when you start to use package
declarations in your code and start getting that exception again:

http://www.yoda.arachsys.com/java/packages.html

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error :java.lang.classdefnotfound: pandit Java 3 12-30-2007 06:02 AM
Exception of type 'System.Web.HttpUnhandledException' wasthrown.Exception has been thrown by the target of an invocation.System.WebSystem.Exception jobs ASP .Net 1 11-16-2007 05:57 PM
ClassDefNotFound error with xpath.evaluate... drakaan@gmail.com Java 9 04-13-2007 08:06 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
Applet not found by IE6 under XP (ClassDefNotFound) Jim Java 4 02-15-2004 11:51 PM



Advertisments