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

微笑、不失礼 提交于 2019-11-29 15:56:39

问题


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);
    }
}

回答1:


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.




回答2:


Please, also check to have ADT installed on Eclipse.



来源:https://stackoverflow.com/questions/11435315/android-os-bundle-cannot-be-resolved-in-libgdx-android-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!