0

今天我开始在 AndEngine 上工作,并且很早就遇到了问题。尝试了一些示例代码来将背景设置为某种颜色,它会抛出 ClassNotFoundException。尝试清理项目,更改工作区。需要一些帮助...

这是我的课

    package com.Try4;

    import org.anddev.andengine.engine.Engine;
    import org.anddev.andengine.engine.camera.Camera;
    import org.anddev.andengine.engine.options.EngineOptions;
    import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
    import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
   import org.anddev.andengine.entity.scene.Scene;
     import org.anddev.andengine.entity.scene.background.ColorBackground;
   import org.anddev.andengine.entity.util.FPSLogger;
     import org.anddev.andengine.ui.activity.BaseGameActivity;

   import android.view.Display;


   public class Try4Activity extends BaseGameActivity{


private Camera mCamera;

private Scene mMainScene;

@Override
public Engine onLoadEngine() {

    final Display display = getWindowManager().getDefaultDisplay();

        int cameraWidth = display.getWidth();

        int cameraHeight = display.getHeight();



        mCamera = new Camera(0, 0, cameraWidth, cameraHeight);



        return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE,

            new RatioResolutionPolicy(cameraWidth, cameraHeight), mCamera));

}

@Override
public void onLoadResources() {


}

@Override
public Scene onLoadScene() {
    mEngine.registerUpdateHandler(new FPSLogger());



        mMainScene = new Scene();

        mMainScene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));

        return mMainScene;


}

@Override
public void onLoadComplete() {


}

}

这是我的 manifest.xml

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

     <uses-sdk android:minSdkVersion="7" />
     <uses-permission android:name="android.permission.WAKE_LOCK"/>
     <uses-permission android:name="android.permission.CAMERA"/>
     <application
     android:icon="@drawable/ic_launcher"
     android:label="@string/app_name" >
     <activity
        android:name=".Try4Activity"
        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>

堆栈跟踪

 05-20 07:28:56.015: W/dalvikvm(351): threadid=3: thread exiting with uncaught exception              (group=0x4001b188)
 05-20 07:28:56.045: E/AndroidRuntime(351): Uncaught handler: thread main exiting due to    uncaught exception
05-20 07:28:56.065: E/AndroidRuntime(351): java.lang.RuntimeException: Unable to   instantiate activity ComponentInfo{com.Try4/com.Try4.Try4Activity}:     java.lang.ClassNotFoundException: com.Try4.Try4Activity in loader   dalvik.system.PathClassLoader@44c066a8
05-20 07:28:56.065: E/AndroidRuntime(351):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
05-20 07:28:56.065: E/AndroidRuntime(351):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
05-20 07:28:56.065: E/AndroidRuntime(351):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
05-20 07:28:56.065: E/AndroidRuntime(351):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
05-20 07:28:56.065: E/AndroidRuntime(351):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-20 07:28:56.065: E/AndroidRuntime(351):  at android.os.Looper.loop(Looper.java:123)
05-20 07:28:56.065: E/AndroidRuntime(351):  at android.app.ActivityThread.main(ActivityThread.java:4363)
05-20 07:28:56.065: E/AndroidRuntime(351):  at java.lang.reflect.Method.invokeNative(Native Method)
05-20 07:28:56.065: E/AndroidRuntime(351):  at java.lang.reflect.Method.invoke(Method.java:521)
05-20 07:28:56.065: E/AndroidRuntime(351):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-20 07:28:56.065: E/AndroidRuntime(351):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-20 07:28:56.065: E/AndroidRuntime(351):  at dalvik.system.NativeStart.main(Native Method)
05-20 07:28:56.065: E/AndroidRuntime(351): Caused by: java.lang.ClassNotFoundException:  com.Try4.Try4Activity in loader dalvik.system.PathClassLoader@44c066a8
05-20 07:28:56.065: E/AndroidRuntime(351):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
05-20 07:28:56.065: E/AndroidRuntime(351):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
05-20 07:28:56.065: E/AndroidRuntime(351):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
05-20 07:28:56.065: E/AndroidRuntime(351):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
05-20 07:28:56.065: E/AndroidRuntime(351):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
05-20 07:28:56.065: E/AndroidRuntime(351):  ... 11 more
05-20 07:28:56.086: I/dalvikvm(351): threadid=7: reacting to signal 3
05-20 07:28:56.106: I/dalvikvm(351): Wrote stack trace to '/data/anr/traces.txt'
4

2 回答 2

1

您不应该在包名中使用大写字母...应该是com.try4.Try4Activity

于 2012-05-20T07:47:52.553 回答
0

问题出在清单文件的这一行中:

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

而是使用这个:

<activity
    android:name="package.subpackage.projectname.Try4Activity"
    android:label="@string/app_name" >
于 2015-03-29T11:43:56.707 回答