DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2003
    Posts
    6

    Exception in thread

    Okay, I'm brand spankin' new to Java, but not programming.

    Here's a very simple application for which I am receiving an error.

    public class CoolJava {

    public static void main (String args[])
    {
    System.out.println("Java is Cool");
    }

    }

    I have the Java 2 SDK, ver 1.3.1 installed on a Win2K platform. After installing it I adjusted the Windows path to include the ".../bin" directory; rebooted the computer.

    The above was created in a text editor and saved as "CoolJava.java". I opened the command prompt and changed directories to that containing this file.

    Next, I typed "javac CoolJava.java". It compiled to bytecode without a hitch, producing the file "CoolJava.class".

    Finally, I typed "java CoolJava" to create the executable. Herein lies the problem. I received the following message.

    "Exception in thread "main" java.lang.NoClassDefFoundError: CoolJava"

    Argh. Why?

    Your feedback is greatly appreciated.


    Respectfully,

    ASP

  2. #2
    Join Date
    Jan 2003
    Posts
    5
    Hi,

    Did you set your classpath as well? Here is an example of a path and classpath setting.

    path=C:\Program Files\Java\j2sdk1.4.0_03\bin;
    set CLASSPATH=C:\Program Files\Java\j2re1.4.0_03\lib\rt.jar;

    This is almost definately the cause of the classnotfound exception.

    Hope this helped.

    Michael

  3. #3
    Join Date
    Dec 2003
    Posts
    6
    Michael,

    Thanks for you reply.

    Well, although I did not make it clear, my intention was to deliberately avoid setting an environment variable for the Classpath.

    It turns out I did a little more research and found a solution. Since I was keeping both the ".java" and ".class" files in the same directory, I only needed to identify the current directory for the source files.

    So, for example...

    javac <myFile>.java - compiles to Java bytecode

    ...and while in the same directory as the newly compiled file...

    java cp . <myFile>.class

    That worked.


    Respectfully,

    ASP

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links