简体   繁体   中英

(LibGDX Android) Unable to instantiate activity ComponentInfo ClassNotFoundException

I have imported the projects created by gdx-setup in Eclipse. There is no error but when I tried to launch the application in my phone or in an emulator, the app crash and I have these messages in my Logcat : Logcat. Here is my code in my android class :

import android.os.Bundle;

import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.mygdx.game.MyGdxGame;

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

Here is my android buildpath.

I know this is a common problem but I've tried many solutions and nothing work. Sorry for the bad english.

Thanks for your help.

Since the default name for Android starter class in AndroidLauncher I assume you renamed it to AndroidGame and some important parts in the code where not updated:

/android/build.gradle:

Look for line like this: commandLine "$adb", 'shell', 'am', 'start', '-n', 'de.tomgrill.someandroidpackage.android/de.tomgrill.android.AndroidLauncher'

The part before the / must match the package name in the AndroidManifest.xml

In my case:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="de.tomgrill.someandroidpackage.android"
......

The part after the / must match the AndroidLauncher class incl. package.

here: de.tomgrill.android.AndroidLauncher

package: de.tomgrill.android

class: AndroidLauncher

Also make sure that the launcher class for the activity in your AndroidManifest.xml fits:

<application
        ...... >
        <activity
            android:name="de.tomgrill.android.AndroidLauncher"
           .....>
            <intent-filter>
                <...... />
            </intent-filter>
        </activity>
    </application>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM