Robby Smet
Robby Smet

Reputation: 4661

NoSuchMethodError: getSize

I have the following code to find the size of the screen:

WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
    Point size = new Point();
    int measuredWidth = 0;
    int measuredHeight = 0;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        wm.getDefaultDisplay().getSize(size);

        measuredWidth = size.x;
        measuredHeight = size.y;
    } else {
        Display display = wm.getDefaultDisplay();

        measuredWidth = display.getWidth();
        measuredHeight = display.getHeight();
    }

On a galaxy gio (2.3.6) this works, but on a galaxy tab 10.1 (3.0) this crashes.

wm.getDefaultDisplay().getSize(size);

On this line I get

NoSuchMethodError: android.view.Display.getSize.

How can I fix this?

Upvotes: 1

Views: 1005

Answers (2)

jakk
jakk

Reputation: 1213

getSize() is since API 13 docs

You probably run this on a device having an older version.

Try getHeight() and getWidth().

Upvotes: 0

Robby Smet
Robby Smet

Reputation: 4661

I already found it, I tought that the getSize() method was available since HoneyComb (api 11), but it's actually only available since Honeycomb_MR2 (api 13).

Upvotes: 2

Related Questions