Results 1 to 7 of 7

Thread: Random Java Error

  1. #1
    Join Date
    May 2008
    Location
    Ontario, Canada
    Beans
    Hidden!
    Distro
    Ubuntu

    Question Random Java Error

    Code:
    -----
    I have this strange Java Error.
    does anyone know what causes it?

    ****@***-laptop:~/2AA4-Sfwr_Design/Assignments/Assig4$ javac NodeT.javaNodeT.java:16: cannot find symbol
    symbol : constructor PointT()
    location: class PointT
    {
    ^
    1 error
    Last edited by vandorjw; March 6th, 2009 at 05:47 PM. Reason: academic integrity

  2. #2
    Join Date
    Sep 2008
    Beans
    87
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Random Java Error

    It says the error is in your PointT class. Could you post it for us?
    Last edited by C--; March 6th, 2009 at 01:38 AM.

  3. #3
    Join Date
    May 2008
    Location
    Ontario, Canada
    Beans
    Hidden!
    Distro
    Ubuntu

    Question Re: Random Java Error

    This is PointT. It compiles without problems or errors however. Maybe I don't quite understand how inheritance works.

    Code:
     -- academic integrity --
    A simple google search will turn up my code for other students to copy. That is why I removed it.
    Last edited by vandorjw; March 6th, 2009 at 02:11 AM.

  4. #4
    Join Date
    Sep 2008
    Beans
    87
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Random Java Error

    Change the NodeT constructor.

    Code:
     EDIT: Code removed for cc7
    Also get rid of the xc and yc variables in the NodeT class.

    Try that and let me know if it works. I'll explain why this works if it does.
    Last edited by C--; March 6th, 2009 at 03:28 AM.

  5. #5
    Join Date
    May 2008
    Location
    Ontario, Canada
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Random Java Error

    Thanks that works.
    +1

    explain please?

  6. #6
    Join Date
    Sep 2008
    Beans
    87
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Random Java Error

    Quote Originally Posted by cc7gir View Post
    Thanks that works.
    +1

    explain please?
    In Java, when you create an instance of an object, the class constructor of that object's class needs to call the constructor of it's superclass. This is required so that you cannot override a superclass constructor; doing so would destroy inheritance.

    In your NodeT class, you did not call PointT's constructor. So, the compiler helped you out by inserting a call to the default constructor for you. The default constructor is always the constructor without arguments, in this case, PointT().

    Normally the default constructor is also provided in a class by the compiler, unless you provide your own constructor. You wrote the PointT(double x, double y) constructor, so the compiler didn't create a default constructor for you. So when the compiler tried to call PointT() from from NodeT(double x, double y, nodeTypeT nt), it couldn't find it because it didn't exist. Hence, the error.

    super(x,y) explicitly calls the superclass constructor that has those two arguments, so the compiler does not try and call the default constructor, which fixes the error.

    Also, we got rid of the xc and yc variables in NodeT because it inherits those variables from PointT, and it can treat them as its own variables (without setters and getters) because you declared them as protected. Therefore it would be redundant to include another declaration in NodeT.

    Hope that helps

  7. #7
    Join Date
    May 2008
    Location
    Ontario, Canada
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Random Java Error

    It does. Thank you for helping solve this so quick, and for the explanation. (the explanation being the more valuable of the two)

    Cheers - CC7

Tags for this Thread

Bookmarks

Posting Permissions

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