0

When I try to create a new instance of the class Point

Point nir = new Point(double x, double y);

I'm getting the error

Multiple markers at this line
   - x cannot be resolved to a variable 
   - y cannot be resolved to a variable

How come? I want x and y to be general, not specific. I want to include my Point as a field of a new class.

EDIT:

In a given class named Circle I want to replace the fields x0 and y0, that represent the coordinates of a point, with an object of type Point. So this is the begining of the class Circle that I want to refactor as above:

public class Circle {

   private double x0, y0, radius;

So, I basically want to change the representation of x0, y0 to Point structure.

7
  • 2
    can you show code, not javadoc? Commented Mar 25, 2011 at 19:33
  • 2
    Can you post the actual code that is giving the error. Commented Mar 25, 2011 at 19:34
  • 1
    Please show us more relevant code Commented Mar 25, 2011 at 19:34
  • 1
    Please read a basic Java tutorial, you are currently using Stack Overflow as your compiler. Commented Mar 25, 2011 at 19:36
  • 2
    @Nir, there is this small, insignificant, unknown site by a company named “Google.” You should look it up on Altavista. Commented Mar 25, 2011 at 19:55

5 Answers 5

6

The error you're getting is that this code

new Point(double x, double y);

is not legal Java. When you create an object or call a function, you do not specify the types of the arguments. Instead, you just provide a value of that type. So, for example, you could create a point by writing

Point origin = new Point(0.0, 0.0);

Or

double x = 137.0;
double y = 2.71828;
Point myPoint = new Point(x, y);

Because in both cases the compiler already knows the types of the expressions you're providing as constructor arguments. You don't need to (and in fact should not) say that they're doubles.

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

Point nir= new Point(x, y);

If that doesn't work, show more code.

Comments

0

You need to create the instance like so:

Point nir = new Point(x, y);

Or like so:

Point nir = new Point(15.0, 12.0);

where x and y are doubles. You're getting an error because you can't specify the type for arguments when calling a constructor, so Point nir = new Point(double x, double y); causes an error.

Comments

0

x and y have to already made:

so do:

Point nir = new Point(x, y);

Comments

0

You're trying to set the parameters when it's expecting arguments. Try:

Point nir= new Point(x, y);

Or:

Point nir= new Point((double) x, (double) y);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.