所以我遇到了一些錯誤,我搜查了起來。看來我有一些內存問題。但我不太清楚如何解決它。這裏的代碼,我相信問題在於,還有錯誤日誌。任何幫助,將不勝感激下面Android錯誤:內存問題?
static List<Dragon> mdragon = new ArrayList<Dragon>();
private int mdragon_number = 0;
@Override
public boolean onTouchEvent(MotionEvent event) {
synchronized (mdragon) {
mdragon.add(new Dragon(getResources(), (int) event.getX(),
(int) event.getY()));
mdragon_number = mdragon.size();
}
return super.onTouchEvent(event);
}
public void Remove(long elapsed, Canvas canvas) {
synchronized (mdragon) {
List<Dragon> toRemove = new ArrayList<Dragon>();
for (Dragon dragon : mdragon) {
if (Condition to remove an element)
toRemove.add(dragon);
}
mdragon.removeAll(toRemove);
}
}
錯誤日誌:
07-13 02:11:46.814: ERROR/AndroidRuntime(280): FATAL EXCEPTION: main
07-13 02:11:46.814: ERROR/AndroidRuntime(280): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
07-13 02:11:46.814: ERROR/AndroidRuntime(280): at android.graphics.Bitmap.nativeCreate(Native Method)
07-13 02:11:46.814: ERROR/AndroidRuntime(280): at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
07-13 02:11:46.814: ERROR/AndroidRuntime(280): at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
07-13 02:11:46.814: ERROR/AndroidRuntime(280): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
07-13 02:11:46.814: ERROR/AndroidRuntime(280): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
07-13 02:11:46.814: ERROR/AndroidRuntime(280): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
07-13 02:11:46.814: ERROR/AndroidRuntime(280): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
07-13 02:11:46.814: ERROR/AndroidRuntime(280): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:346)
07-13 02:11:46.814: ERROR/AndroidRuntime(280): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:372)