Results 1 to 2 of 2
  1. #1
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Richmond, Virginia
    Blog Entries
    Rep Power

    Default Compiling packages

    I am having a bit of trouble with compiling items in packages.

    I am making classes for shape, with circle, square, triangle extending from shape. I am saving them all in the same directory and packaging them with the directory name
    Java Code:
    package Polymorphism.shape;
    All classes are public and in the same directory, if I have one class reference another I have to compile in a weird seeming way
    Java Code:
    for another function in the same directory which uses everything I have to compile with
    Java Code:
    It seems inefficient to have to compile any other classes an item uses when I want to compile. Is there something I am doing wrong?

    The final part of the example I am trying to run is to fill an array with shapes and randomshapegenerator, then make method calls on each of them, when I try compiling the final shapes class, which imports polymorphism.shape.*;

    I managed to get shapes to compile but Im still running into error messages related to randomshapegenerator, I have the program copied word for word from the text and it doesn't work correctly, which is quite frustrating.

    When I run the final class which uses randomshapegenerator to make items I get the following error:
    Java Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: polymorphism/shape/Ra
    ndomShapeGenerator (wrong name: Polymorphism/shape/RandomShapeGenerator)
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClassCond(Unknown Source)
            at java.lang.ClassLoader.defineClass(Unknown Source)
            at Source)
            at Source)
            at$000(Unknown Source)
            at$ Source)
            at Method)
            at Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at Shapes.<clinit>(
    Could not find the main class: Shapes.  Program will exit.
    Last edited by sunde887; 01-10-2011 at 06:25 AM. Reason: added another problem

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power


    Your Polymorhpism directory starts with a capital 'P', whereas it would seem the polymorphism package declared in RandomShapeGenerator does not.

    Java is case sensitive.

Similar Threads

  1. Packages
    By urbim in forum Eclipse
    Replies: 2
    Last Post: 07-02-2009, 03:01 PM
  2. packages
    By fogus in forum New To Java
    Replies: 1
    Last Post: 03-24-2009, 07:14 AM
  3. Replies: 3
    Last Post: 02-12-2008, 12:03 PM
  4. packages
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 07-31-2007, 01:10 PM

Posting Permissions

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