Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By Tolls

Thread: java.lang.ClassNotFoundException

  1. #1
    oim415 is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default java.lang.ClassNotFoundException

    I am currently working through the book "Sams Teach yourself Java 6 in 21 days" and am on Day 6. Today's lesson is about using packages. I have created a Storefront application consisting of two classes -Storefront and Item. These classes are organized in a package, org.im.ecommerce.

    I have set the CLASSPATH variable as .;c:\Program Files\java\jdk1.6.0_01\lib\tools.jar;c:\dev\java

    The Storefront.class and Item.class files are in the c:\dev\java\org\im\ecommerce folder.

    I have a second application called GiftShop that uses the aforementioned classes. This application compiles successfully but when I try to execute it, we get the java.lang.ClassNotFoundException

    Here is a snippet of code from each file.

    GiftShop.java

    import org.im.ecommerce.*;

    public class GiftShop {

    public static void main(String[] arguments) {
    Storefront store = new Storefront();
    //body of program
    }

    Storefront.java

    package org.im.ecommerce;

    import java.util.*;

    public class Storefront {
    //body of program
    }

    Item.java

    package org.im.ecommerce;

    import java.util.*;

    public class Item implements Comparable {

    //body of program
    }


    This is direct from the console.
    %PROGRAMFILES%\jEdit> java -classpath "$CLASSPATH;C:\Users\Oscar\Documents\workspace " -ms32m -mx32m GiftShop
    Exception in thread "main" java.lang.NoClassDefFoundError: org/im/ecommerce/Storefront
    at GiftShop.main(GiftShop.java:6)
    Process java exited with code 1

    What else can I be looking at? Your help is greatly appreciated.

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: java.lang.ClassNotFoundException

    If you are using Windows to access an environment variable from the terminal use %VARIABLE_NAME% not $VARIABLE_NAME. In your case the get the CLASSPATH variable you should %CLASSPATH%.

  3. #3
    oim415 is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: java.lang.ClassNotFoundException

    It's working now. thanks

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: java.lang.ClassNotFoundException

    I would recommend not setting up an environment variable for the classpath, except as a local one.
    System wide classpaths for Java are not a good thing.
    DarrylBurke likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. java.lang.ClassNotFoundException - Issue
    By C.phantasy in forum New To Java
    Replies: 3
    Last Post: 11-05-2012, 05:58 AM
  2. java.lang.ClassNotFoundException
    By djgovins in forum Java Servlet
    Replies: 4
    Last Post: 07-25-2011, 12:54 PM
  3. Replies: 8
    Last Post: 11-04-2010, 02:46 PM
  4. java.lang.ClassNotFoundException
    By ravian in forum New To Java
    Replies: 1
    Last Post: 01-07-2008, 11:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •