2012-05-20 78 views
0

今天我開始研究AndEngine並且很早就面臨問題。嘗試了一些示例代碼來將背景設置爲某種顏色,並拋出ClassNotFoundException。試圖清理項目,改變工作區。需要一些幫助......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 [email protected] 
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 [email protected] 
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' 
+0

請添加堆棧跟蹤。 – rekire

+0

@rekire添加了它的伴侶。 – dnivra

+0

您是否嘗試「清潔」該項目? –

回答

1

你不應該在包名稱中使用大寫字母...應該是com.try4.Try4Activity

+0

你要我重構包或只是改變其用途在manifest.xml中? – dnivra

+0

重構一切 – nebkat

0

的問題是在這條線的清單文件中:

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

而是使用此:

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