Results 1 to 10 of 10
Thread: Error Compiling Project in BlueJ
- 06-15-2011, 05:58 AM #1
Member
- Join Date
- Jun 2011
- Posts
- 9
- Rep Power
- 0
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!
- 06-15-2011, 06:02 AM #2
I have no idea. This is not a BlueJ forum.
It would seem you are attempting to call a constructor in the CoordinateSystem class that does not exist.Compiling gives an error of "cannot find symbol - constructor CoordinateSystem(int,int,java.awt.Image)".
Either call a constructor that does exist or add another constructor that does accept those parameters.How do I fix this?
- 06-15-2011, 06:02 AM #3
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
You need to add a constructor for the class, then create an instance of the object and call methods on the instance.
- 06-15-2011, 06:07 AM #4
Member
- Join Date
- Jun 2011
- Posts
- 9
- Rep Power
- 0
What exactly is the constructor and how do I add it? I'm sure the class CoordinateSystem exists, because that compiled fine. Thanks!
-
Please read your text book or tutorials or notes, I'm sure this is covered.
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.I'm sure the class CoordinateSystem exists, because that compiled fine. Thanks!
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.
- 06-15-2011, 04:40 PM #6
Member
- Join Date
- Jun 2011
- Posts
- 9
- Rep Power
- 0
CoordinateSystem class:
Foot 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; } }
I noted where BlueJ found the error. I also attached a screenshot of my project: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); } }

Thanks!
- 06-15-2011, 08:43 PM #7
Member
- Join Date
- Mar 2011
- Posts
- 34
- Rep Power
- 0
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
-
So you're calling the CoordinateSystem constructor like so:
But your CoordinateSystem class currently has only one constructor:Java Code:coordinates = 'new CoordinateSystem(x, y, pic);
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.Java Code:public CoordinateSystem() { // initialise instance variables x = 0;
- 06-15-2011, 10:51 PM #9
Member
- Join Date
- Jun 2011
- Posts
- 9
- Rep Power
- 0
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!
- 06-17-2011, 08:04 PM #10
Member
- Join Date
- Jun 2011
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
BlueJ help! weird error text meesed up
By linux1man in forum Other IDEsReplies: 6Last Post: 02-07-2013, 03:54 PM -
Compiling/Running Project in Command Line: "Could not find main class" Error
By Yasemin Gokce in forum New To JavaReplies: 1Last Post: 06-30-2009, 02:32 PM -
Having error while compiling
By Kodeee in forum New To JavaReplies: 12Last Post: 03-17-2009, 11:08 AM -
Project works in debugger, not after compiling
By Fleur in forum New To JavaReplies: 11Last Post: 05-29-2008, 09:04 AM -
Compiling error
By lawksalih in forum New To JavaReplies: 6Last Post: 01-29-2008, 07:26 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks