Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Where is my .class?

  1. #1
    Member Scorks's Avatar
    Join Date
    Jan 2013
    Posts
    56
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Where is my .class?

    Hi! I've just finished writing a program, and I keep getting an error stating

    Shapes.java:308: cannot find symbol
    symbol : class ATriangle
    location: class Shapes
    ATriangle ATriangle = new ATriangle(1.0, 2.0, 5.0);

    My program is about superclasses and subclasses, so each new class I make extends the main one (which is AnObject).

    ATriangle, the third subclass, isn't working when I create a new one (giving the error shown above) It looks like this:

    class ATriangle extends AnObject {
     
    double Side1;
    double Side2;
    double Side3;
     
    //No parameter constructor
     
    public ATriangle() {
    double Side1;
    double Side2;
    double Side3;
    }
     
    // 3 parameter constructor
     
    public ATriangle(double s1, double s2, double s3) {
    Side1 = s1;
    Side2 = s2;
    Side3 = s3;
    }
     
    // 5 parameter constructor
     
    public ATriangle(double s1, double s2, double s3, String Colour1, String Filled1) {
    Side1 = s1;
    Side2 = s2;
    Side3 = s3;
    Colour = Colour1;
    Filled = Filled1;
    }
     
    //Accessor and mutator methods for each attribute
     
    public double getSide1() {
    return Side1;
    }
     
    public double getSide2() {
    return Side2;
    }
     
    public double getSide3() {
    return Side3;
    }
     
    public void setSide1(double s1) {
    Side1 = s1;
    }
     
    public void setSide2(double s2) {
    Side2 = s2;
    }
     
    public void setSide3(double s3) {
    Side3 = s3;
    }
     
    //AREA ACCESSOR
     
    public double getArea() {
    double s = (Side1 + Side2 + Side3) / 2;
    double Area = Math.sqrt( s*(s - Side1)*(s - Side2)*(s - Side3) );
    return Area;
    }
     
    public double getPerimeter() {
    double Perimeter = Side1 + Side2 + Side3;
    return Perimeter;
    }
     
    //TOSTRING METHOD 
     
    public String toString() {
    return "\n" + "Side1 : " + Side1 + "\n" + "Side2 : " + Side2 + "\n" + "Side3 : " + Side3;
     
    }
     
    }

    An my main class is:

    public class Shapes {
    public static void main (String[] args) {
     
    //Test AnObject: 
    System.out.println("TESTING THE SUPERCLASS (OBJECT) : " + "\n");
    AnObject object = new AnObject("Green", "Filled");
    System.out.println(object.getColour());
    System.out.println(object.getFilled());
    object.setColour("Blue");
    object.setFilled("Not Filled");
    System.out.println(object.toString() + "\n");
     
    //Test ACircle
    System.out.println("TESTING THE CIRCLE! : " + "\n");
    ACircle circle = new ACircle("Yellow", "Not Filled", 4.0);
    circle.setRadius(5.0);
    System.out.println(circle.getRadius());
    System.out.println("Area : " + circle.getArea());
    System.out.println("Perimeter : " +circle.getPerimeter());
    System.out.println("Diameter : " +circle.getDiameter());
    System.out.println(circle.toString() + "\n");
     
    //Test ARectangle
    System.out.println("TESTING THE RECTANGLE! : " + "\n");
    ARectangle rectangle = new ARectangle(5.0, 3.0, "Red", "Filled");
    System.out.println("Width : " + rectangle.getWidth());
    System.out.println("Length: " + rectangle.getLength());
    rectangle.setWidth(10.0);
    rectangle.setLength(2.0);
    System.out.println("Area : " + rectangle.getArea());
    System.out.println("Perimeter: " + rectangle.getPerimeter());
    System.out.println(rectangle.toString());
     
    //Test ATriangle
    System.out.println("TESTING THE ATRIANGLE! : " + "\n");
    ATriangle triangle = new ATriangle(1.0, 2.0, 5.0);
     
       }
    }

    Can anyone see why this isn't working?

    --- Update ---

    Also, I think it's important to not that both ARectangle and ACircle have ARectangle.class and ACircle.class when I search it under my finder, but ATriangle does not.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,726
    My Mood
    Mellow
    Thanks
    172
    Thanked 622 Times in 609 Posts

    Default Re: Where is my .class?

    I don't see a problem with what you posted. Are all class source files in the same folder?

  3. #3
    Member Scorks's Avatar
    Join Date
    Jan 2013
    Posts
    56
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Where is my .class?

    That's the problem! When I try to look for ATriangle.class, all that comes up is ACircle$ATriangle.class and ARectangle$ATriangle.class, but none are just ATriangle.class ...

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,726
    My Mood
    Mellow
    Thanks
    172
    Thanked 622 Times in 609 Posts

    Default Re: Where is my .class?

    I didn't ask about the .class files, but that's an interesting answer nonetheless. Try deleting all of the .class files and recompiling the project.

  5. #5
    Member Scorks's Avatar
    Join Date
    Jan 2013
    Posts
    56
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Where is my .class?

    I did that, and now I'm getting the same problem, except now it happens with ARectangle aswell.

  6. #6
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Where is my .class?

    Declare your classes as public.

  7. #7
    Member Scorks's Avatar
    Join Date
    Jan 2013
    Posts
    56
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Where is my .class?

    public class ATriangle extends AnObject {
     
    double Side1;
    double Side2;
    double Side3;
     
    //No parameter constructor
     
    public ATriangle() {
    double Side1;
    double Side2;
    double Side3;
    }
     
    // 3 parameter constructor
     
    public ATriangle(double s1, double s2, double s3) {
    Side1 = s1;
    Side2 = s2;
    Side3 = s3;
    }
     
    // 5 parameter constructor
     
    public ATriangle(double s1, double s2, double s3, String Colour1, String Filled1) {
    Side1 = s1;
    Side2 = s2;
    Side3 = s3;
    Colour = Colour1;
    Filled = Filled1;
    }
     
    //Accessor and mutator methods for each attribute
     
    public double getSide1() {
    return Side1;
    }
     
    public double getSide2() {
    return Side2;
    }
     
    public double getSide3() {
    return Side3;
    }
     
    public void setSide1(double s1) {
    Side1 = s1;
    }
     
    public void setSide2(double s2) {
    Side2 = s2;
    }
     
    public void setSide3(double s3) {
    Side3 = s3;
    }
     
    //AREA ACCESSOR
     
    public double getArea() {
    double s = (Side1 + Side2 + Side3) / 2;
    double Area = Math.sqrt( s*(s - Side1)*(s - Side2)*(s - Side3) );
    return Area;
    }
     
    public double getPerimeter() {
    double Perimeter = Side1 + Side2 + Side3;
    return Perimeter;
    }
     
    //TOSTRING METHOD 
     
    public String toString() {
    return "\n" + "Side1 : " + Side1 + "\n" + "Side2 : " + Side2 + "\n" + "Side3 : " + Side3;
     
    }
     
    }

    I did this (made the classes public) to everything, and just received the same error...

  8. #8
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,726
    My Mood
    Mellow
    Thanks
    172
    Thanked 622 Times in 609 Posts

    Default Re: Where is my .class?

    There's something about the way this project is setup that you're not telling us - not that you're being purposely deceptive, you just don't realize it's important. The results described in post #3 indicate there's more going on here than we know. So let's go back to basics:

    Is every class that you've mentioned defined in its own .java source file, properly named, ClassName.java?

    Are all .java source files for all of the classes a member of the same package, even default?

    Are all .java source files for all of the classes in the same folder?

    If the answer is "No" to any of the above, please describe the differences.

  9. #9
    Member Scorks's Avatar
    Join Date
    Jan 2013
    Posts
    56
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Where is my .class?

    All I have is the Shapes.java file, then four others called AnObject.class, ACircle.class, ACircle$ARectangle.class, and ACircle$ATriangle.class on their own.

Similar Threads

  1. Replies: 2
    Last Post: November 18th, 2012, 01:09 PM
  2. need to make basic class and implementation class (base class without void main)
    By javanewbie101 in forum Object Oriented Programming
    Replies: 1
    Last Post: September 19th, 2012, 08:03 PM
  3. create a test class (main method) to start(run) the class in Java
    By curious725 in forum Java Theory & Questions
    Replies: 5
    Last Post: August 1st, 2012, 03:21 AM
  4. Replies: 3
    Last Post: June 17th, 2012, 06:22 PM
  5. Replies: 3
    Last Post: April 13th, 2011, 03:30 PM

Tags for this Thread