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 10 of 10

Thread: Error in constructor

  1. #1
    Member
    Join Date
    Jul 2011
    Posts
    31
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Error in constructor

    I have a constructor that is in a class that extends and abstract class and am getting this error message when I compile Class 4

    cannot find symbol
    symbol : constructor AbstractClass1()
    location: class Abstract1

    public class MyTimes extends AbstractClass1

    //MyTimes constructor
    public MyTimes(Class3Object startTime, Class3Object endTime) {

    this.startTime = startTime;
    this.endTime = endTime;

    } //end constructor

    My AbstractClass1 has the same constructor and definition as above.

    The class MyTimes extends another class, which itself extends to another class like below.
    Example:
    Class 4 extends AbstractClass1
    Class 3 extends class 2
    Class 2 extends class 1
    Last edited by hello_world; August 13th, 2011 at 06:55 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Error in constructor

    cannot find symbol
    symbol : constructor AbstractClass1()
    location: class Abstract1
    What is the relationship between Abstract1 and AbstractClass1?
    Your post does not show any Abstract1.

    What line in your code was the error on?
    Last edited by Norm; August 13th, 2011 at 07:46 PM.

  3. #3
    Member
    Join Date
    Jul 2011
    Posts
    31
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Error in constructor

    Abstract1 is the default constructor in AbstractClass1.
    Abstract1 looks exactly like the constuctor above in MyTimes
    The error comes when I compile the MyTimes class, so to me the issue is with how I have my constructor build in MyTimes and the abstract to which it extends. The MyTimes constructor is after my class instance variables which must be "protected".
    They are also identified as protected in my AbstractClass1.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Error in constructor

    Abstract1 is the default constructor in AbstractClass1.
    You'll have to post some actual code. The names of constructor and class must match. Your comment makes no sense.

  5. #5
    Member
    Join Date
    Jul 2011
    Posts
    31
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Error in constructor

    Heres the code from my abstract class.

    public abstract class PhoneCall {

    //Instance Variables of type CheckedTime
    protected CheckedTime startTime;
    protected CheckedTime endTime;

    /*
    A public constructor that accepts two CheckedTime objects,
    one for the start time and one for the finish.
    */
    public PhoneCall(CheckedTime startTime, CheckedTime endTime) {

    this.startTime = startTime;
    this.endTime = endTime;

    } //end constructor method
    }

    Here's the code from my other class. There are more classes, but these are the ones causing the compile error.
    public class LocalCall extends PhoneCall {

    //Class variables
    CheckedTime startTime;
    CheckedTime endTime;

    private double totalCallLength = 0;
    private double totalCost = 0;

    //Constants
    static final double LOCAL_COST = .01;
    static final int HUNDMIN_to_SEC = 6000;

    //LocalCall constructor
    public LocalCall(CheckedTime startTime, CheckedTime endTime) {

    this.startTime = startTime;
    this.endTime = endTime;

    } //end constrctor

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Error in constructor

    Your code does NOT call the super class's constructor, so the compiler wants to add a call to the default constructor which does not exist.
    Either call the super constructor or add a default constructor.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Error in constructor

    The sub class's variable names are the same as the base class's variable names.
    Do you intended to mask the base class variables?

  8. #8
    Member
    Join Date
    Jul 2011
    Posts
    31
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Error in constructor

    No, I wanted to get access to them. I used super (variable1, variable2) and it compiled.

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Error in constructor

    Is your problem solved now?

  10. #10
    Member
    Join Date
    Jul 2011
    Posts
    31
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Error in constructor

    Yes sir, thank you

Similar Threads

  1. Junit3 error: Implicit super constructor TestCase() is not visible
    By albertkao in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 21st, 2011, 12:53 PM
  2. Point constructor
    By upad in forum What's Wrong With My Code?
    Replies: 11
    Last Post: October 5th, 2010, 07:34 PM
  3. how to initialise set in a constructor
    By davie in forum Collections and Generics
    Replies: 3
    Last Post: March 12th, 2010, 05:35 PM
  4. Private Constructor
    By Ganezan in forum Object Oriented Programming
    Replies: 4
    Last Post: November 7th, 2009, 04:02 PM
  5. Replies: 2
    Last Post: November 3rd, 2009, 06:28 AM