Andoid get resolution of the screen

Hi everyone,

I’m trying to set a point on the guiNode, at (3/4 of width, 1/4 of height).
I’m using the following code for that:

private void getDimensions() {
        GraphicsDevice grapics = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        
        DisplayMode[] modes = grapics.getDisplayModes();
        
        width = modes[0].getWidth();
        height = modes[0].getHeight();
    }

It gives me an error at the first line:

Exception thrown in Thread[GLThread …
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/awt/GraphicsEnviroment
bla bla at line 103 bla bla mygame.Main bla bla.

Am I doing something wrong or is this just not the way to approach Android?

you’d better use:

int width = guiViewPort.getCamera().getWidth();
int height = guiViewPort.getCamera().getheight();

It will work regardless of the target platform

4 Likes

I’ll try it tomorrow. My temporary solution is to channel it from the Activity.