PDA

Click to See Complete Forum and Search --> : [RESOLVED] Problem creating object


Acronim
May 23rd, 2009, 01:24 PM
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:



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:


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...


...
...
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.

Acronim
May 24th, 2009, 02:59 AM
Never mind, I figured it out.
A good night's rest fixed it :P

No, seriously... Of course, I shouldn't have put "void" in the constructors.
It works fine now ^^

ComputerJy
May 24th, 2009, 05:39 AM
You can also mark the Thread resolved so people know you're problem is was solved even before opening this page :)

Acronim
May 24th, 2009, 07:31 AM
Yeah, sorry... I did look for how to do that, but I didn't see the option... I found it now, though (As you can see) ^^