我使用 contentView “gameView” 它扩展了 SurfaceView 并且我使用线程对我的游戏进行永久循环,我的 onCreate() 方法是
public class mainclass extends Activity {
GameView game;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
game = new GameView(this);
setContentView(game);
}
崩溃日志猫是
05-09 09:35:06.378: W/dalvikvm(9664): threadid=1: thread exiting with uncaught exception (group=0x40015560)
05-09 09:35:06.388: E/AndroidRuntime(9664): FATAL EXCEPTION: main
05-09 09:35:06.388: E/AndroidRuntime(9664): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
05-09 09:35:06.388: E/AndroidRuntime(9664): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
05-09 09:35:06.388: E/AndroidRuntime(9664): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
05-09 09:35:06.388: E/AndroidRuntime(9664): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
05-09 09:35:06.388: E/AndroidRuntime(9664): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:359)
05-09 09:35:06.388: E/AndroidRuntime(9664): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:385)
05-09 09:35:06.388: E/AndroidRuntime(9664): at superBill.Mbiz.Egypt.GameView.<init>(GameView.java:87)
05-09 09:35:06.388: E/AndroidRuntime(9664): at superBill.Mbiz.Egypt.SuperBillActivity.onCreate(SuperBillActivity.java:20)
05-09 09:35:06.388: E/AndroidRuntime(9664): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-09 09:35:06.388: E/AndroidRuntime(9664): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
05-09 09:35:06.388: E/AndroidRuntime(9664): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-09 09:35:06.388: E/AndroidRuntime(9664): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-09 09:35:06.388: E/AndroidRuntime(9664): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-09 09:35:06.388: E/AndroidRuntime(9664): at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 09:35:06.388: E/AndroidRuntime(9664): at android.os.Looper.loop(Looper.java:130)
05-09 09:35:06.388: E/AndroidRuntime(9664): at android.app.ActivityThread.main(ActivityThread.java:3683)
05-09 09:35:06.388: E/AndroidRuntime(9664): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 09:35:06.388: E/AndroidRuntime(9664): at java.lang.reflect.Method.invoke(Method.java:507)
05-09 09:35:06.388: E/AndroidRuntime(9664): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-09 09:35:06.388: E/AndroidRuntime(9664): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-09 09:35:06.388: E/AndroidRuntime(9664): at dalvik.system.NativeStart.main(Native Method)
注意:此崩溃发生在第二次,但第三次正常,第四次崩溃,第五次正常,依此类推。