Search code examples
androidlinuxcrashlibgdx

Libgdx app crashes on Android: Could not find class 'java.awt.Rectangle',


I have a problem with running project on android device. When I run it as desktop app everything is fine. I tried to run it on other devices but results were same.

Here is the .java code from core project:

public class UGame extends ApplicationAdapter {
    private SpriteBatch batch;
    private Texture leftPaddleImage;
    private Rectangle leftPaddle;
    private OrthographicCamera camera;

    @Override
    public void create () {
        batch = new SpriteBatch();

        leftPaddleImage = new Texture(Gdx.files.internal("LeftPaddle_.png"));
        camera = new OrthographicCamera();
        camera.setToOrtho(false, 800, 480);

        leftPaddle= new Rectangle();
        leftPaddle.x=0;
        leftPaddle.y=(480/2) - 43;
        leftPaddle.height=80;
        leftPaddle.width=20;
    }

    @Override
    public void render () {
        Gdx.gl.glClearColor(1, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        camera.update();
        batch.setProjectionMatrix(camera.combined);

        batch.begin();
        batch.draw(leftPaddleImage, leftPaddle.x, leftPaddle.y );
        batch.end();

        if(Gdx.input.isKeyPressed(Keys.W)) {
            leftPaddle.y+=200*Gdx.graphics.getDeltaTime();
        }

        if(Gdx.input.isKeyPressed(Keys.S)) {
            leftPaddle.y-=200*Gdx.graphics.getDeltaTime();
        }
    }
} 

here is LogCat output:

03-04 22:06:29.728: D/ActivityThread(9937): handleBindApplication:com.studiU.qPyong.android
03-04 22:06:29.738: D/ActivityThread(9937): setTargetHeapUtilization:0.25
03-04 22:06:29.738: D/ActivityThread(9937): setTargetHeapMinFree:524288
03-04 22:06:29.838: D/dalvikvm(9937): Trying to load lib /data/app-lib/com.studiU.qPyong.android-2/libgdx.so 0x41b459b8
03-04 22:06:29.858: D/dalvikvm(9937): Added shared lib /data/app-lib/com.studiU.qPyong.android-2/libgdx.so 0x41b459b8
03-04 22:06:29.858: D/dalvikvm(9937): No JNI_OnLoad found in /data/app-lib/com.studiU.qPyong.android-2/libgdx.so 0x41b459b8, skipping init
03-04 22:06:29.868: E/dalvikvm(9937): Could not find class 'java.awt.Rectangle', referenced from method com.studiU.qPyong.UGame.create
03-04 22:06:29.868: W/dalvikvm(9937): VFY: unable to resolve new-instance 1007 (Ljava/awt/Rectangle;) in Lcom/studiU/qPyong/UGame;
03-04 22:06:29.868: D/dalvikvm(9937): VFY: replacing opcode 0x22 at 0x0027
03-04 22:06:29.878: W/dalvikvm(9937): VFY: unable to resolve instance field 5355
03-04 22:06:29.878: D/dalvikvm(9937): VFY: replacing opcode 0x52 at 0x002a
03-04 22:06:29.878: D/dalvikvm(9937): DexOpt: unable to opt direct call 0x2c85 at 0x29 in Lcom/studiU/qPyong/UGame;.create
03-04 22:06:29.888: I/Adreno200-EGL(9937): <qeglDrvAPI_eglInitialize:290>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_JB.04.01.01.00.005_msm7627a_JB_CL2577695_release_AU (CL2577695)
03-04 22:06:29.888: I/Adreno200-EGL(9937): Build Date: 07/11/12 Wed
03-04 22:06:29.888: I/Adreno200-EGL(9937): Local Branch: mybranch65565
03-04 22:06:29.888: I/Adreno200-EGL(9937): Remote Branch: quic/master
03-04 22:06:29.888: I/Adreno200-EGL(9937): Local Patches: NONE
03-04 22:06:29.888: I/Adreno200-EGL(9937): Reconstruct Branch: AU_LINUX_ANDROID_JB.04.01.01.00.005 + db7e81a + 4568683 + dfff884 +  NOTHING
03-04 22:06:30.038: I/AndroidInput(9937): sensor listener setup
03-04 22:06:30.098: I/AndroidInput(9937): sensor listener tear down
03-04 22:06:30.139: I/Adreno200-EGL(9937): <qeglDrvAPI_eglInitialize:290>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_JB.04.01.01.00.005_msm7627a_JB_CL2577695_release_AU (CL2577695)
03-04 22:06:30.139: I/Adreno200-EGL(9937): Build Date: 07/11/12 Wed
03-04 22:06:30.139: I/Adreno200-EGL(9937): Local Branch: mybranch65565
03-04 22:06:30.139: I/Adreno200-EGL(9937): Remote Branch: quic/master
03-04 22:06:30.139: I/Adreno200-EGL(9937): Local Patches: NONE
03-04 22:06:30.139: I/Adreno200-EGL(9937): Reconstruct Branch: AU_LINUX_ANDROID_JB.04.01.01.00.005 + db7e81a + 4568683 + dfff884 +  NOTHING
03-04 22:06:30.209: D/OpenGLRenderer(9937): Enabling debug mode 0
03-04 22:06:30.439: I/Timeline(9937): Timeline: Activity_idle id: android.os.BinderProxy@41b3c998 time:11125210
03-04 22:06:31.640: W/IInputConnectionWrapper(9937): beginBatchEdit on inactive InputConnection
03-04 22:06:31.640: W/IInputConnectionWrapper(9937): endBatchEdit on inactive InputConnection

Solution

  • Android has its own graphics library, you won't be able to use java.awt libraries in android. (The Rectangle class

    03-04 22:06:29.868: W/dalvikvm(9937): VFY: unable to resolve new-instance 1007 (Ljava/awt/Rectangle;) in Lcom/studiU/qPyong/UGame;
    

    You will need to find some alterantive libraries to do what you want, have a look at the one presented in LibGDX - Conditionally use java or android classes

    The libgdx libraries might be able to do what your looking for. http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/package-summary.html

    Try using the Polygon class