33

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);
    }
}
P.T.
  • 24,557
  • 7
  • 64
  • 95
Coder Shark
  • 437
  • 2
  • 5
  • 13

2 Answers2

56

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.

P.T.
  • 24,557
  • 7
  • 64
  • 95
  • Thanks that's done the trick! Since I installed the AndroidSDK a long time ago I neglected this step. Everything's working fine now. Cheers! – Coder Shark Jul 12 '12 at 07:48
  • @DengkeSha Glad that helped! I see you're new to StackOverflow. Please click the "answered" checkmark so folks know this question is satisfactorily answered. See: http://stackoverflow.com/faq#howtoask. Thanks! – P.T. Jul 12 '12 at 16:53
  • Thanks a lot P.T.! You're right, I'm new. After using stackoverflow for quite a while I finally decided to register. I've marked the question answered now. Thanks for being so helpful. Cheers! :) – Coder Shark Jul 13 '12 at 23:52
  • 1
    totally helped me.. I was wandering around in "Configure Build Path" blindly – bad_keypoints Dec 29 '12 at 05:09
  • Something is not right with Eclipse. I had my project working well and then suddenly it started throwing that error. I did what P.T. suggested and only one target was selected already. So I changed to some other and it started working. Then I switched back to old one and it worked again?! – MilanG Jan 25 '15 at 11:07
  • Spoke too soon. After this I can run the project, but starting and screen switching takes forever. – MilanG Jan 25 '15 at 11:32
  • I was hitting this error as well, had gone into my project properties and selected the Android build target and was still hitting the error. In my case i simply needed to restart eclipse for it to resolve the issue :\ – Kenneth Wilke Mar 20 '17 at 20:10
  • @P.T. I think I've a similar problem: https://stackoverflow.com/q/54851229/6367213 Only eclipse ADT plugin is no longer supported - https://developer.android.com/studio/tools/sdk/eclipse-adt – Janez Kuhar Mar 11 '19 at 17:07
4

Please, also check to have ADT installed on Eclipse.

yaircarreno
  • 4,002
  • 1
  • 34
  • 32