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

    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:
    c:\javacode\Polymorphism\shape
    
    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:
    javac shape.java circle.java
    for another function in the same directory which uses everything I have to compile with
    Java Code:
    javac shape.java circle.java square.java triangle.java randomshapegenerator.java
    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 java.security.SecureClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.access$000(Unknown Source)
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown 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>(shapes.java:5)
    Could not find the main class: Shapes.  Program will exit.
    Last edited by sunde887; 01-10-2011 at 05:25 AM. Reason: added another problem

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,809
    Rep Power
    19

    Default

    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, 02:01 PM
  2. packages
    By fogus in forum New To Java
    Replies: 1
    Last Post: 03-24-2009, 06:14 AM
  3. Replies: 3
    Last Post: 02-12-2008, 11:03 AM
  4. packages
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 07-31-2007, 12: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
  •