|
-
May 23rd, 2009, 01:24 PM
#1
Thread Starter
New Member
[RESOLVED] Problem creating object
Sorry if this has been asked before, but to be very honest... I am lazy :P.
My problem is probably a simple one.
I am just starting to learn Java, because I have to. We're going quite rapidly in class.
Edit:
I figured it out already :P... Just edited this here, so that you don't read through all this to then find out I already found my mistake. Thanks
I just read the part in the book on objects, and tried making my assignment, but there is one problem...
I created a class with some constructors, which I want to use to create objects of course.
The following way to create an object and pass values to it works:
Code:
public class Part1 {
public static void main(String[] args) throws IOException {
...
...
RecCoord point2 = new RecCoord();
point2.setRecCoord(coords[0][1], coords[1][1]);
...
...
}
}
I use a class I wrote, which begins with:
Code:
class RecCoord {
// Create variables
private double xval;
private double yval;
private boolean equal;
private double distance;
// Create Constructors
public void RecCoord() {
// Set values to 0
xval = 0;
yval = 0;
}
public void RecCoord(double xval, double yval) {
// Set user-defined values
this.xval = xval;
this.yval = yval;
}
// Create methods
public void setRecCoord(double xval, double yval) {
// Set user-defined values
this.xval = xval;
this.yval = yval;
}
...
...
However, the following gives me compiler error, but I don't understand why...
Code:
...
...
RecCoord point2 = new RecCoord(coords[0][1], coords[1][1]);
...
...
Perhaps I misunderstood something from the book, but I thought this should work...
Of course, coords[][] is an array with double entries.
By the way, I use ConTEXT, and the somewhat cryptic error message says:
"Part1.java:35: cannot resolve symbol
symbol : constructor RecCoord(double, double)
location: class RecCoord
RecCoord point2 = new RecCoord(coords[0][1], coords[1][1]);
1 error"
Also, if I use the first way, everything (the entire program to test the class) works as expected...
I would really appreciate any help.
Last edited by Acronim; May 24th, 2009 at 03:02 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|