user1841377
user1841377

Reputation: 19

The method getX() is undefined for the type Point

I am getting the method getX() is undefined for the type Point

my code is

public void addNewPoints(Point p)   {
    dataset.add(p.getX(), p.getY());
}

please help me how resolve this error

Upvotes: 1

Views: 1312

Answers (3)

David Allan Houser Jr
David Allan Houser Jr

Reputation: 127

under source generate getters and setters but first you need something to get and set like this

class Point{
private int x;
private int y;

public void addNewPoints(Point p)   {
 dataset.add(p.getX(), p.getY());
}
}

Its a long story why private variables public methods to get and set variables, encapsulation, best practice.

Upvotes: 0

mah
mah

Reputation: 39807

You're confusing java.awt.Point with android.graphics.Point. The Android Point, documented at http://developer.android.com/reference/android/graphics/Point.html, has public int x and int y data members, while the AWT Point does have the getX() method.

Upvotes: 0

Andro Selva
Andro Selva

Reputation: 54322

Its because the class Point doesn't contain a public method named getX().

Upvotes: 1

Related Questions