Results 1 to 10 of 10
  1. #1
    java1337 is offline Member
    Join Date
    Jun 2011
    Posts
    9
    Rep Power
    0

    Default Error Compiling Project in BlueJ

    What are the arrows in BlueJ for? I am working on the the First Steps project in Chapter 3 of Java Methods by Litvin, and right now, I have the Walker, Foot, and CoordinateSystem classes in a project. Compiling gives an error of "cannot find symbol - constructor CoordinateSystem(int,int,java.awt.Image)". How do I fix this?

    Thanks in advance!

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,759
    Rep Power
    7

    Default

    Quote Originally Posted by java1337 View Post
    What are the arrows in BlueJ for?
    I have no idea. This is not a BlueJ forum.

    Compiling gives an error of "cannot find symbol - constructor CoordinateSystem(int,int,java.awt.Image)".
    It would seem you are attempting to call a constructor in the CoordinateSystem class that does not exist.

    How do I fix this?
    Either call a constructor that does exist or add another constructor that does accept those parameters.

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

    Default

    You need to add a constructor for the class, then create an instance of the object and call methods on the instance.

  4. #4
    java1337 is offline Member
    Join Date
    Jun 2011
    Posts
    9
    Rep Power
    0

    Default

    What exactly is the constructor and how do I add it? I'm sure the class CoordinateSystem exists, because that compiled fine. Thanks!

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by java1337 View Post
    What exactly is the constructor and how do I add it?
    Please read your text book or tutorials or notes, I'm sure this is covered.

    I'm sure the class CoordinateSystem exists, because that compiled fine. Thanks!
    That's not the issue. The issue is that you're calling a constructor for this class that doesn't exist. Check the constructors that the class has and only call one that exists.

    If you're still confused, post your CoordinateSystem class code here, and show us how you're trying to use, it, especially the code that is causing your error to occur.

  6. #6
    java1337 is offline Member
    Join Date
    Jun 2011
    Posts
    9
    Rep Power
    0

    Default

    CoordinateSystem class:

    Java Code:
    /**
     * Write a description of class CoordinateSystem here.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
    public class CoordinateSystem
    {
        // instance variables - replace the example below with your own
        private int x;
    
        /**
         * Constructor for objects of class CoordinateSystem
         */
        public CoordinateSystem()
        {
            // initialise instance variables
            x = 0;
        }
    
        /**
         * An example of a method - replace this comment with your own
         * 
         * @param  y   a sample parameter for a method
         * @return     the sum of x and y 
         */
        public int sampleMethod(int y)
        {
            // put your code here
            return x + y;
        }
    }
    Foot class:
    Java Code:
    // Represents a foot, used for displaying walking creatures.
    
    import java.awt.Image;
    import java.awt.Graphics;
    
    public class Foot
    {
      private Image picture;
      private CoordinateSystem coordinates;
    
      // Constructor
      public Foot(int x, int y, Image pic)
      {
        picture = pic;
        coordinates = new CoordinateSystem(x, y, pic); BLUEJ FINDS AN ERROR IN THIS LINE
      }
    
      // Moves this foot forward by distance pixels
      // (or backward if distance < 0).
      public void moveForward(int distance)
      {
        coordinates.shift(distance, 0);
      }
    
      // Moves this foot sideways by distance pixels
      // (to the right if distance  > 0 or to the left
      // if distance < 0).
      public void moveSideways(int distance)
      {
        coordinates.shift(0, distance);
      }
    
      // Turns this foot (clockwise for degrees > 0).
      public void turn(int degrees)
      {
        coordinates.rotate(Math.PI * degrees / 180.0);
      }
    
      // Draws this foot in the appropriate coordinate system.
      public void draw(Graphics g)
      {
        coordinates.drawImage(g, picture);
      }
    }
    I noted where BlueJ found the error. I also attached a screenshot of my project:
    Error Compiling Project in BlueJ-firststepsscreenshot.jpg

    Thanks!

  7. #7
    elliotHenry is offline Member
    Join Date
    Mar 2011
    Posts
    34
    Rep Power
    0

    Default

    Hello java1337

    I'm a bit of a noobie here too and will probably get shot by the more senior members here but Sundie, Junky and Fubarable have basically given you the answer.

    Have a look at your constructor in the CoordinateSystem class and then look at how you construct the new object in the foot class. See the issue here?

    Good Luck

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    So you're calling the CoordinateSystem constructor like so:

    Java Code:
    coordinates = 'new CoordinateSystem(x, y, pic);
    But your CoordinateSystem class currently has only one constructor:
    Java Code:
        public CoordinateSystem()
        {
            // initialise instance variables
            x = 0;
    But this constructor takes no parameters (note the empty parenthesis () on its first line). I suggest that you give your coordinate system some variables. It already has an x variable, but perhaps you want to give it a y and a pic variable, and then create a constructor that accepts three parameters and then initialize your variables with the parameters. Again, your text/notes/tutorials will have an example of how to do this, and I suggest that you study it.

  9. #9
    java1337 is offline Member
    Join Date
    Jun 2011
    Posts
    9
    Rep Power
    0

    Default

    Thanks for all the help! I think I fixed the issue so now I have three classes, Walker, Foot, and CoordinateSystem, and all of them compile fine. How do I build a jar file that shows two walkers walking across the floor? When I just click "Build jar file" in BlueJ, I get a choice of what to use as my main class. The "none" option produces something that is non-executable, and I tried to use one of the classes I wrote as the main class, but this produces the error message "Fatal error occurred. Program will exit."

    Thanks!

  10. #10
    java1337 is offline Member
    Join Date
    Jun 2011
    Posts
    9
    Rep Power
    0

Similar Threads

  1. BlueJ help! weird error text meesed up
    By linux1man in forum Other IDEs
    Replies: 6
    Last Post: 02-07-2013, 03:54 PM
  2. Replies: 1
    Last Post: 06-30-2009, 02:32 PM
  3. Having error while compiling
    By Kodeee in forum New To Java
    Replies: 12
    Last Post: 03-17-2009, 11:08 AM
  4. Project works in debugger, not after compiling
    By Fleur in forum New To Java
    Replies: 11
    Last Post: 05-29-2008, 09:04 AM
  5. Compiling error
    By lawksalih in forum New To Java
    Replies: 6
    Last Post: 01-29-2008, 07:26 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
  •