KarneeKarnay
Newbie
I am very new to development on Android phones and started to use AndEngine today. Ran into a weird bug when I was following a basic tutorial. Whenever I run this tutorial example on my tablet it says that the app just fails to work. As far as I can tell the problem is that it doesn't even compile. Any ideas?
Error output below:
Error output below:
05-27 20:30:01.243: E/Trace(8707): error opening trace file: No such file or directory (2)
05-27 20:30:01.283: W/dalvikvm(8707): Unable to resolve superclass of Lcom/example/gametest/MainActivity; (649)
05-27 20:30:01.283: W/dalvikvm(8707): Link of class 'Lcom/example/gametest/MainActivity;' failed
05-27 20:30:01.283: D/AndroidRuntime(8707): Shutting down VM
05-27 20:30:01.283: W/dalvikvm(8707): threadid=1: thread exiting with uncaught exception (group=0x40caa2a0)
05-27 20:30:01.283: E/AndroidRuntime(8707): FATAL EXCEPTION: main
05-27 20:30:01.283: E/AndroidRuntime(8707): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.gametest/com.example.gametest.MainActivity}: java.lang.ClassNotFoundException: com.example.gametest.MainActivity
05-27 20:30:01.283: E/AndroidRuntime(8707): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
05-27 20:30:01.283: E/AndroidRuntime(8707): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
05-27 20:30:01.283: E/AndroidRuntime(8707): at android.app.ActivityThread.access$600(ActivityThread.java:130)
05-27 20:30:01.283: E/AndroidRuntime(8707): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
05-27 20:30:01.283: E/AndroidRuntime(8707): at android.os.Handler.dispatchMessage(Handler.java:99)
05-27 20:30:01.283: E/AndroidRuntime(8707): at android.os.Looper.loop(Looper.java:137)
05-27 20:30:01.283: E/AndroidRuntime(8707): at android.app.ActivityThread.main(ActivityThread.java:4745)
05-27 20:30:01.283: E/AndroidRuntime(8707): at java.lang.reflect.Method.invokeNative(Native Method)
05-27 20:30:01.283: E/AndroidRuntime(8707): at java.lang.reflect.Method.invoke(Method.java:511)
05-27 20:30:01.283: E/AndroidRuntime(8707): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-27 20:30:01.283: E/AndroidRuntime(8707): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-27 20:30:01.283: E/AndroidRuntime(8707): at dalvik.system.NativeStart.main(Native Method)
05-27 20:30:01.283: E/AndroidRuntime(8707): Caused by: java.lang.ClassNotFoundException: com.example.gametest.MainActivity
05-27 20:30:01.283: E/AndroidRuntime(8707): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
05-27 20:30:01.283: E/AndroidRuntime(8707): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-27 20:30:01.283: E/AndroidRuntime(8707): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-27 20:30:01.283: E/AndroidRuntime(8707): at android.app.Instrumentation.newActivity(Instrumentation.java:1063)
05-27 20:30:01.283: E/AndroidRuntime(8707): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
05-27 20:30:01.283: E/AndroidRuntime(8707): ... 11 more
Code:
package com.example.gametest;
import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.ui.activity.BaseGameActivity;
public class MainActivity extends BaseGameActivity {
// scenes
Scene scene;
// camera
protected static final int CAMERA_WIDTH = 800;
protected static final int CAMERA_HEIGHT = 480;
// Textures
BitmapTextureAtlas playerTexture;
ITextureRegion playerTextureRegion;
@Override
public EngineOptions onCreateEngineOptions() {
Camera mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
EngineOptions options = new EngineOptions(true,
ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(
CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
return options;
}
@Override
// Loads all the resources used. Eg. Spritesheets, images, sounds, textures.
public void onCreateResources(
OnCreateResourcesCallback pOnCreateResourcesCallback)
throws Exception {
// TODO Auto-generated method stub
// resources finished.
loadGfx();
pOnCreateResourcesCallback.onCreateResourcesFinished();
}
private void loadGfx() {
// TODO Auto-generated method stub
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("GFX/");
// width and height 2 to x.
playerTexture = new BitmapTextureAtlas(getTextureManager(), 50, 50);
playerTextureRegion = BitmapTextureAtlasTextureRegionFactory
.createFromAsset(playerTexture, this, "player.png", 0, 0);
playerTexture.load();
}
@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)
throws Exception {
// TODO Auto-generated method stub
this.scene = new Scene();
this.scene.setBackground(new Background(0, 125, 58));
pOnCreateSceneCallback.onCreateSceneFinished(this.scene);
}
@Override
public void onPopulateScene(Scene pScene,
OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {
// TODO Auto-generated method stub
Sprite sPlayer = new Sprite(CAMERA_WIDTH / 2, CAMERA_HEIGHT / 2,
playerTextureRegion,this.mEngine.getVertexBufferObjectManager());
sPlayer.setRotation(45.0f);
this.scene.attachChild(sPlayer);
pOnPopulateSceneCallback.onPopulateSceneFini[/syntax]shed();
}
}
