Programs run fine with LibGDX -desktop but not LibGDX - Android?

…衆ロ難τιáo~ 提交于 2019-12-23 11:28:27

问题


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.



来源:https://stackoverflow.com/questions/23094436/programs-run-fine-with-libgdx-desktop-but-not-libgdx-android

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