android.os.Bundle不能libgdx Android项目来解决项目、os、android、Bundle

2023-09-06 01:32:21 作者:良人已不在

我刚刚开始使用 Libgdx 练习做游戏,我使用,只要在网站上的项目创建的.jar创建最初的项目。然而,一个错误出现在Android的项目,说:

  

android.os.Bundle不能得到解决。

我使用的Eclipse的Java IDE。如果我把光标放在 AndroidApplication 这是红色下划线,它表明我配置构建路径。我相信我已经安装了Android SDK,因为它在一个简单的例子项目工作了一段时间后在不同的工作区。有谁知道我可能会在这个新的工作区做错了?我该如何配置构建路径, AndroidApplication 类?

顺便说一句,我相信我使用Java 1.6的,这就是JAVA_HOME指向,虽然我也得到了1.7的Java安装。这可能是不相关的,但...

 包com.example.drop;

进口android.os.Bundle;
进口com.badlogic.gdx.backends.android.AndroidApplication;
进口com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;

公共类MainActivity扩展AndroidApplication {
    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);

        AndroidApplicationConfiguration CFG =新AndroidApplicationConfiguration();
        cfg.useGL20 = FALSE;
        cfg.useAccelerometer = FALSE;
        cfg.useCompass = FALSE;

        初始化(新的投递(),CFG);
    }
}
 

解决方案

您所看到的错误与Android SDK的配置,而不​​是特定于libGDX。编译器不知道编译针对其Android的库。

正确使用LibGDX教程设置你的项目。 (看到 https://github.com/libgdx/libgdx/wiki/Manual-project-setup#android-project-setup. 在那里的第一个步骤做了Android特有的设置。)

libgdx 安装 Android SDK

如果您不希望创建一个新的项目,但解决现有的项目,下面的步骤应该配置一个项目,建立针对Android的:

在在Eclipse Package Explorer中右键单击项目 选择属性并选择安卓部分 确保正是其中的工程建设目标被选中。

这应该添加所需的Andr​​oid库的构建路径作为一种副作用。

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

解决方案

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:

right-click on the project in the Eclipse Package Explorer select Properties and pick the Android section 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.