为什么我的应用程序不能在我的设备上运行? java.lang.ClassNotFoundException:com.example.spaceyspace.BaseActivity

时间:2014-03-30 22:21:39

标签: java android eclipse logcat

帮助我是Android编程的新手,但我想更多地看一下,我正在跟踪this website关于创建基于Space Invaders的小应用程序的教程。我无法让我的应用程序从Eclipse运行我只得到LogCat输出错误打开跟踪文件:没有这样的文件或目录(2)。

我的Logcat的其余部分如下所示:

03-30 23:05:00.758: E/Trace(19674): error opening trace file: No such file or directory (2)
03-30 23:05:00.808: D/AndroidRuntime(19674): Shutting down VM
03-30 23:05:00.808: W/dalvikvm(19674): threadid=1: thread exiting with uncaught exception(group=0x4193a318)
03-30 23:05:00.818: E/AndroidRuntime(19674): FATAL EXCEPTION: main
03-30 23:05:00.818: E/AndroidRuntime(19674): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.spaceyspace/com.example.spaceyspace.BaseActivity}: java.lang.ClassNotFoundException: com.example.spaceyspace.BaseActivity
03-30 23:05:00.818: E/AndroidRuntime(19674):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1987)
03-30 23:05:00.818: E/AndroidRuntime(19674):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2088)
03-30 23:05:00.818: E/AndroidRuntime(19674):    at android.app.ActivityThread.access$600(ActivityThread.java:134)
03-30 23:05:00.818: E/AndroidRuntime(19674):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)
03-30 23:05:00.818: E/AndroidRuntime(19674):    at android.os.Handler.dispatchMessage(Handler.java:99)
03-30 23:05:00.818: E/AndroidRuntime(19674):    at android.os.Looper.loop(Looper.java:137)
03-30 23:05:00.818: E/AndroidRuntime(19674):    at android.app.ActivityThread.main(ActivityThread.java:4744)
03-30 23:05:00.818: E/AndroidRuntime(19674):    at java.lang.reflect.Method.invokeNative(Native Method)
03-30 23:05:00.818: E/AndroidRuntime(19674):    at java.lang.reflect.Method.invoke(Method.java:511)
03-30 23:05:00.818: E/AndroidRuntime(19674):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-30 23:05:00.818: E/AndroidRuntime(19674):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-30 23:05:00.818: E/AndroidRuntime(19674):    at dalvik.system.NativeStart.main(Native Method)
03-30 23:05:00.818: E/AndroidRuntime(19674): Caused by: java.lang.ClassNotFoundException: com.example.spaceyspace.BaseActivity
03-30 23:05:00.818: E/AndroidRuntime(19674):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
03-30 23:05:00.818: E/AndroidRuntime(19674):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
03-30 23:05:00.818: E/AndroidRuntime(19674):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
03-30 23:015:00.818: E/AndroidRuntime(19674):   at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
03-30 23:05:00.818: E/AndroidRuntime(19674):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1978)
03-30 23:05:00.818: E/AndroidRuntime(19674):    ... 11 more

请帮帮我

感谢Mattyhammers

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.util.FPSLogger;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.font.FontFactory;
import org.andengine.ui.activity.SimpleBaseGameActivity;

import android.graphics.Typeface;


public class BaseActivity extends SimpleBaseGameActivity {

    static final int CAMERA_WIDTH = 800;
static final int CAMERA_HEIGHT = 480;

public Font mFont;
public Camera mCamera;

public Scene mCurrentScene;
public static BaseActivity instance;

public EngineOptions onCreateEngineOptions(){
    instance = this;
    mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

    return new EngineOptions(true, ScreenOrientation.LANDSCAPE_SENSOR, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
}

protected void onCreateResources(){
    mFont = FontFactory.create(this.getFontManager(), this.getTextureManager(), 256, 256, Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 32);
    mFont.load();
}

protected Scene onCreateScene(){
    mEngine.registerUpdateHandler(new FPSLogger());
    mCurrentScene = new Scene();
    mCurrentScene.setBackground(new Background(0.09804f, 0.7274f, 0.8f));
    return mCurrentScene;
}

}

1 个答案:

答案 0 :(得分:1)

您没有名为com.example.spaceyspace.BaseActivity的类。

03-30 23:05:00.818: E/AndroidRuntime(19674): Caused by: java.lang.ClassNotFoundException: com.example.spaceyspace.BaseActivity

您可能有一个名为BaseActivity的类,但它的全名不是com.example.spaceyspace.BaseActivity。您应该检查该文件的包名称并进行修复。您的问题都在错误消息中描述。修复它们,从前面带有“由...引起”的那些开始。

请参阅备选方案的评论。请注意,当您处理错误消息时,您为修复错误所做的工作和重复出现的错误的组合将缩小您的真实问题。