2012-10-22 177 views
1

我是一個初學者,我相信我的代碼都很好,但是當在模擬器中加載應用程序時,應用程序崩潰,需要強制關閉。我得到了波紋管logcat,我搜查了錯誤,但說實話,我不明白足以轉換他們的其他解決方案,以適應我(我試過)Surfaceview - 致命異常:主要

編輯:從我可以告訴從其他線程我可能需要向清單添加什麼東西?

有人可以向我解釋什麼,我應該在我的代碼中尋找與波紋管logcat或至少指向我的東西,我可以嘗試?

如果還有其他事情我可以幫助解決這個問題id非常有必要它的接縫我的很多項目都是由同樣的錯誤引發的瘟疫。

感謝提前的所有幫助,這是我的第一篇文章,所以要很好:)

logcat的

10-22 20:59:20.258: D/AndroidRuntime(307): Shutting down VM 

10-22 20:59:20.258: W/dalvikvm(307): threadid=1: thread exiting with uncaught   
exception (group=0x4001d800) 

10-22 20:59:20.348: E/AndroidRuntime(307): FATAL EXCEPTION: main 

10-22 20:59:20.348: E/AndroidRuntime(307): java.lang.RuntimeException: Unable to  
instantiate activity 
ComponentInfo{com.example.w1_t2_surfaceview/com.example.w1_t2_surfaceview.MyGame}:  
java.lang.ClassNotFoundException: com.example.w1_t2_surfaceview.MyGame in loader  
dalvik.system.PathClassLoader[/data/app/com.example.w1_t2_surfaceview-2.apk] 

10-22 20:59:20.348: E/AndroidRuntime(307): at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585) 

10-22 20:59:20.348: E/AndroidRuntime(307): at 
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 

10-22 20:59:20.348: E/AndroidRuntime(307): at 
android.app.ActivityThread.access$2300(ActivityThread.java:125) 

10-22 20:59:20.348: E/AndroidRuntime(307): at 
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 

10-22 20:59:20.348: E/AndroidRuntime(307): at 
android.os.Handler.dispatchMessage(Handler.java:99) 

10-22 20:59:20.348: E/AndroidRuntime(307): at android.os.Looper.loop(Looper.java:123) 

10-22 20:59:20.348: E/AndroidRuntime(307): at 
android.app.ActivityThread.main(ActivityThread.java:4627) 

10-22 20:59:20.348: E/AndroidRuntime(307): at 
java.lang.reflect.Method.invokeNative(Native Method) 

10-22 20:59:20.348: E/AndroidRuntime(307): at 
java.lang.reflect.Method.invoke(Method.java:521) 

10-22 20:59:20.348: E/AndroidRuntime(307): at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 

10-22 20:59:20.348: E/AndroidRuntime(307): at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 

10-22 20:59:20.348: E/AndroidRuntime(307): at dalvik.system.NativeStart.main(Native 
Method) 

10-22 20:59:20.348: E/AndroidRuntime(307): Caused by: 
java.lang.ClassNotFoundException: com.example.w1_t2_surfaceview.MyGame in loader 
dalvik.system.PathClassLoader[/data/app/com.example.w1_t2_surfaceview-2.apk] 

10-22 20:59:20.348: E/AndroidRuntime(307): at 
dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243) 

10-22 20:59:20.348: E/AndroidRuntime(307): at 
java.lang.ClassLoader.loadClass(ClassLoader.java:573) 

10-22 20:59:20.348: E/AndroidRuntime(307): at 
java.lang.ClassLoader.loadClass(ClassLoader.java:532) 

10-22 20:59:20.348: E/AndroidRuntime(307): at 
android.app.Instrumentation.newActivity(Instrumentation.java:1021) 

10-22 20:59:20.348: E/AndroidRuntime(307): at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577) 

10-22 20:59:20.348: E/AndroidRuntime(307): ... 11 more 

MyGame類 包com.example.game;

import android.app.Activity; 
import android.os.Bundle; 
import android.view.Window; 

public class MyGame extends Activity { 
/** Called when the activity is first created. */ 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(new GameView(this)); 
} 
} 

遊戲視圖類 package com.example.game; import com.example.w1_t2_surfaceview.R;

import android.content.Context; 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.graphics.Canvas; 
import android.graphics.Color; 
import android.view.SurfaceView; 


public class GameView extends SurfaceView { 
private Bitmap bmp; 

public GameView(Context context) { 
     super(context); 
     bmp = BitmapFactory.decodeResource(getResources(), R.drawable.icon); 
} 
@Override 
protected void onDraw(Canvas canvas) { 
    canvas.drawColor(Color.CYAN); 
    canvas.drawBitmap(bmp, 10, 10, null); 
} 
} 
由於是開放1周

清單

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" /> 

<application android:label="@string/app_name" 
    android:icon="@drawable/ic_launcher" 
    android:theme="@style/AppTheme"> 
    <activity 
     android:name=".MyGame" 
     android:label="@string/title_surfaceview" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

</manifest> 

的strings.xml

<resources> 
<string name="app_name">W1_T2_SurfaceView</string> 
<string name="title_surfaceview">Surface View 2</string> 
</resources> 

碰碰線程。

回答

0

我想這可能只是一個與Android模擬器使用GLSurfaceView相關的問題。試用一個實際的設備,看看會發生什麼。