ClassDefNotFound Exception

Discussion in 'Java' started by Steve Burrus, May 27, 2004.

  1. Steve Burrus

    Steve Burrus Guest

    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!!!
     
    Steve Burrus, May 27, 2004
    #1
    1. Advertising

  2. Steve Burrus

    Roedy Green Guest

    On Thu, 27 May 2004 04:28:09 GMT, Steve Burrus <>
    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/errormessages.html#NOCLASSDEFFOUNDERROR
    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, May 27, 2004
    #2
    1. Advertising

  3. 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
     
    Gordon Beaton, May 27, 2004
    #3
  4. Steve Burrus

    Steve Burrus Guest

    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) {}
    }
    }
    }
    }"
     
    Steve Burrus, May 27, 2004
    #4
  5. 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
     
    Gordon Beaton, May 28, 2004
    #5
  6. Steve Burrus

    Steve Burrus Guest

    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?
     
    Steve Burrus, May 28, 2004
    #6
  7. 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/tooldocs/windows/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
     
    Gordon Beaton, May 28, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jeff
    Replies:
    0
    Views:
    1,547
  2. jeff
    Replies:
    3
    Views:
    1,714
    Scott
    Jun 26, 2003
  3. Jim
    Replies:
    4
    Views:
    2,302
    Andrew Thompson
    Feb 15, 2004
  4. Replies:
    9
    Views:
    1,452
  5. pandit
    Replies:
    3
    Views:
    643
Loading...

Share This Page