-1

We are trying to draw something with the scene2D from libGDX. We have our main activity then use the extends Androidapplication to initialize our testgame class. Here we define our screen and then make our stage and actors in the screen class.

Problem is that we are getting the same error over and over: >

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gamepadTest.app/com.gamepadTest.app.MainActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.gamepadTest.app/com.gamepadTest.app.TestGame}; have you declared this activity in your   AndroidManifest.xml? 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
            Caused by: java.lang.ClassNotFoundException: Didn't find class     "com.gamepadTest.app.MainActivity" on path: DexPathList[[zip file     "/data/app/com.gamepadTest.app-1.apk"],nativeLibraryDirectories=[/data/app-   lib/com.gamepadTest.app-1, /system/lib]]
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
            at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
            

> at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at      com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)

Have a look:

import android.os.Bundle;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;

public class MainActivity extends AndroidApplication {
    private TestGame testGame = new TestGame();

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();

        initialize(testGame, cfg);
    }
}

import com.badlogic.gdx.Game;

public class TestGame extends Game
{
    TestScreen testScreen;

    @Override
    public void create() {
        testScreen = new TestScreen();
        setScreen(testScreen);
    }

    @Override
    public void dispose() {
        testScreen.dispose();
    }
}

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.scenes.scene2d.Stage;

public class TestScreen implements Screen {

    private Stage stage;
    private TestActor testActor;

    public TestScreen() {
        stage = new Stage();
        Gdx.input.setInputProcessor(stage);
        testActor = new TestActor();
        stage.addActor(testActor);
    }

    public void resize(int width, int height) {
        stage.setViewport(800, 600, false);
        stage.getCamera().translate(-stage.getGutterWidth(), -stage.getGutterHeight(), 0);
    }

    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
        stage.act(delta);
        stage.draw();
    }

    @Override public void dispose() {
        stage.dispose();
    }
    @Override public void show() {}
    @Override public void hide() {}
    @Override public void pause() {}
    @Override public void resume() {}
}

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.scenes.scene2d.Actor;

public class TestActor extends Actor{

    private ShapeRenderer renderer;

    @Override
    public void act(float delta) {
        super.act(delta);
        renderer = new ShapeRenderer();
    }

    @Override
    public void draw (SpriteBatch batch, float parentAlpha) {
        batch.end();

        renderer.setProjectionMatrix(batch.getProjectionMatrix());
        renderer.setTransformMatrix(batch.getTransformMatrix());
        renderer.translate(getX(), getY(), 0);

        renderer.begin(ShapeRenderer.ShapeType.Point);
        renderer.rect(0, 0, 100, 100);
        renderer.end();

        batch.begin();
    }
}

UPDATE:

Here is my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gamepadTest.app"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="19" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.gamepadTest.app.MainActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
</manifest>
Daahrien
  • 10,190
  • 6
  • 39
  • 71
Jordi Sipkens
  • 595
  • 1
  • 9
  • 25
  • Could you paste more of your stack trace? (It seems that something tries to put your game class where activiy class is expected). – Tomasz Gawel Dec 09 '13 at 15:05
  • I added some more stack trace – Jordi Sipkens Dec 10 '13 at 12:00
  • At first glimpse I do not see anything suspicious in your code. The stack trace did not give a hint I expected, too. Did you generate your project with gdx-setup-tool, or created it "manually"? Do you use eclipse or android studio? – Tomasz Gawel Dec 10 '13 at 13:02
  • Created it manually and i use android studio. However we are only trying to develop the android game, so what we did looks similar to what it suppose to be. Thats why we cant figure out the problem – Jordi Sipkens Dec 10 '13 at 13:59
  • Do you have gdx.jar, gdx-backend-android.jar in libs folder of your project? Are they marked as "exported to dependent projects"? – Tomasz Gawel Dec 10 '13 at 14:08
  • Yes i made a lib folder for that one, had some struggles with importing and a libs folder already existed but wasn't listed. However they got imported succesfully(I guess). Both of them are under dependencies in the file structure menu. – Jordi Sipkens Dec 10 '13 at 14:21
  • Do you have libgdx.so and libandroidgl20.so in /libs/armeabi? – Tomasz Gawel Dec 10 '13 at 14:32
  • No i have no armeabi. – Jordi Sipkens Dec 10 '13 at 14:37
  • So, from gdx.zip copy armeabi and armeabi-v7 folders and paste them (with their contents) into /libs folder of your project. – Tomasz Gawel Dec 10 '13 at 14:44
  • Done and Done, however a different (but of the same kind) error appeared. 12-10 14:41:16.951 10519-10519/com.gamepadTest.app E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.gamepadTest.app/com.gamepadTest.app.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.gamepadTest.app.MainActivity" on path: DexPathList[[zip file "/data/app/com.gamepadTest.app-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.gamepadTest.app-1, /system/lib]] – Jordi Sipkens Dec 10 '13 at 14:46
  • It suggests that the lib gdx jars are in your classpath but are not exported to apk. I do not use android studio. I could tell you how to check it in eclipse. Here I guess: did you put information about your jars to root/project/build.gradle ? – Tomasz Gawel Dec 10 '13 at 14:53
  • It seems that there is a problem with importing so files in android studio. See this topic http://stackoverflow.com/questions/16667903/android-studio-gradle-and-ndk – Tomasz Gawel Dec 10 '13 at 15:16
  • I'll discuss this with my classmates tomorrow on school! Thank you for your time! I really appreciate it :) – Jordi Sipkens Dec 10 '13 at 15:29

2 Answers2

1

You have to declare your activity TestGame inside your AndroidManifest.xml as <activity>

For more info about the manifest: http://developer.android.com/guide/topics/manifest/manifest-intro.html

Should look something like this, and needs to be inside the <application>-tag:

    <activity
        android:name="com.example.TestGame"
        android:label="@string/app_name" >
    </activity>
bbuecherl
  • 1,609
  • 12
  • 20
0

TestGame isn't an Activity:

public class TestGame extends Game{

The Activity you must declare is MainActivity. So its wierd, probably you made another Activity with that same name. But anyway, try setting it with dot notation instead of the whole package:

<activity
    android:name=".TestGame"
    android:label="@string/app_name" >
</activity>

See this: Unable to find explicit activity class

Community
  • 1
  • 1
Daahrien
  • 10,190
  • 6
  • 39
  • 71
  • Not working either, the manifest really says to start the activity with mainactivity. However i still get the shutdown when trying to startup my application. And when trying to declare TestGame as the activity it gives errors. Im really confused lol.. – Jordi Sipkens Dec 10 '13 at 11:51