3

Why following code generate error message : getX() has private access in java.awt.Rectangle (int)dest.getX(), (int)dest.getY(), (int)dest.getWidth(), (int)dest.getHeight()

According to the doc , Rectangle do have a public method getX().

   public boolean setSize(java.awt.Rectangle source, java.awt.Rectangle dest)
{

    setVideoSize((int)source.getX() ,(int)source.getY(), (int)source.getWidth(), (int)source.getHeight(),
              (int)dest.getX(), (int)dest.getY(), (int)dest.getWidth(), (int)dest.getHeight()
     );


     return true;

}
Mat
  • 202,337
  • 40
  • 393
  • 406
pierrotlefou
  • 39,805
  • 37
  • 135
  • 175
  • 1
    Wow, I've never seen that before. Rectangle.getX() was always public, there's absolutely no good reason why this shouldn't compile. Try running javac with the -verbose option, and see if there's anything in the classpath that shouldn't be there. And maybe tell us what version of the JDK you're using. – Mike Baranczak Feb 25 '11 at 03:39
  • interesting that it doesn't complain about source.getX(), only dest.getX(). and those other methods shouldn't be showing in the error message. it's almost as if there were a problem with parentheses, but if there is I can't see it. – jcomeau_ictx Feb 25 '11 at 03:53
  • @jcomeau_ictx: It complained about dest.getX() either. I just simplified the error message. – pierrotlefou Feb 25 '11 at 04:54

3 Answers3

1

I just tried the following and it compiles fine.

public boolean setSize(java.awt.Rectangle source, java.awt.Rectangle dest) {

        setVideoSize((int) source.getX(), (int) source.getY(),
                (int) source.getWidth(), (int) source.getHeight(),
                (int) dest.getX(), (int) dest.getY(), (int) dest.getWidth(),
                (int) dest.getHeight());

        return true;

    }

    private void setVideoSize(int x, int y, int width, int height, int x2,
            int y2, int width2, int height2) {
        // TODO Auto-generated method stub

    }
Bala R
  • 107,317
  • 23
  • 199
  • 210
  • Hi, I am using package from PhoneMe project. Having checked the source code, I found the getX() was declared as private. Don't know why ,anyway. – pierrotlefou Feb 25 '11 at 04:51
1

getX() is private in some specifications of java. For example, jsr-217 does not have getX() has public. Check the specification of java that you are running. If it is private, you might have access the data member directly.

http://docs.oracle.com/javame/config/cdc/ref-impl/pbp1.1.2/jsr217/index.html

goknicks
  • 11
  • 1
0

pierr, getX() works with a more limited program:


jcomeau@intrepid:/tmp$ cat test.java; java test
import java.awt.*;
public class test {
 public static void main(String args[]) {
  Rectangle rect = new Rectangle(0, 0, 1, 1);
  System.out.println("x: " + rect.getX());
 }
}
x: 0.0

I cannot see why yours is erroring, though.

jcomeau_ictx
  • 37,688
  • 6
  • 92
  • 107