Home » Android » java – android.os.Bundle cannot be resolved in libgdx Android project

java – android.os.Bundle cannot be resolved in libgdx Android project

Posted by: admin April 23, 2020 Leave a comment

Questions:

I’ve just started using Libgdx to practice making games and I used the project creation .jar provided on the site to create the initial projects. However an error shows up in the Android project which says:

android.os.Bundle cannot be resolved.

I am using Eclipse for Java IDE. If I put the cursor over AndroidApplication which is underlined in red, it suggests that I configure the build path. I believe I have the Android SDK installed, because it worked a while back on a different workspace on a simple example project. Does anyone know what I might have done wrong in this new workspace? How can I configure the build path for the AndroidApplication class?

BTW, I believe I’m using Java 1.6 as that’s what JAVA_HOME points to, although I’ve also got Java 1.7 installed. That might not be relevant though…

package com.example.drop;

import android.os.Bundle;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;

public class MainActivity extends AndroidApplication {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
        cfg.useGL20 = false;
        cfg.useAccelerometer = false;
        cfg.useCompass = false;

        initialize(new Drop(), cfg);
    }
}
How to&Answers:

The error you are seeing is related to the Android SDK configuration, and is not specific to libGDX. The compiler does not know which Android libraries to compile against.

Use the LibGDX tutorials to setup your projects correctly. (See
https://github.com/libgdx/libgdx/wiki/Manual-project-setup#android-project-setup.
The first step in there does the Android-specific setup.)

If you do not want to create a new project but fix an existing project, the following steps should configure a project to build against Android:

  1. right-click on the project in the Eclipse Package Explorer
  2. select Properties and pick the Android section
  3. Make sure exactly one of the “Project Build Targets” is selected.

That should add the required Android libraries to the build path as a side-effect.

Answer:

Please, also check to have ADT installed on Eclipse.