Programs run fine with LibGDX -desktop but not Lib

2019-06-22 06:59发布

问题:

So I have just set up Eclipse to work with LibGDX using Gradle. After I installed I noticed there was a problem with the Android package, there was a red cross next to the package. When I opened it further there was a red cross next to src then com.myname.game.android and then in AndroidLauncher.java. When I opened the AndroidLauncher.java, this was the code I got:

package com.faturbansloth.game.android;

import android.os.Bundle;

import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.faturbansloth.game.MyGame;

public class AndroidLauncher extends AndroidApplication {
    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration config = new     AndroidApplicationConfiguration();
        initialize(new MyGame(), config);
    }
}    

When I looked at the errors in he code of AndroidLauncher.java they were saying:

-The type android.os.Handler cannot be resolved. It is indirectly referenced from 
required .class files 
-The import android.os.Bundle cannot be resolved
-Multiple markers at this line
- The type android.app.Activity cannot be resolved. It is indirectly referenced from 
 required .class files
- The hierarchy of the type AndroidLauncher is inconsistent
-Bundle cannot be resolved to a type   

I am using SDK Manager 22.6.2 with the newest Gradle plugin for Eclipse. I have JRE 8 and JDK 7. Is there anyway to fix this problem? Thanks in advance.

回答1:

There was no Android Version selected by default, so go: Project -> Properties -> Android -> Project Build Target and select your preferred version



回答2:

I have no idea why this works but it does for me. I installed the ADT plugin, refreshed the android section and the red cross disappeared.

Refer to the section under "Download the ADT Plugin" to install the ADT plugin. http://developer.android.com/sdk/installing/installing-adt.html

After that, go to Eclipse > Package Explorer > Left click on Project-android > Select Refresh.