我的自定义视图在大多数设备上运行良好,但我得到了一些崩溃报告:
java.lang.IllegalArgumentException
bitmap size exceeds 32bits
android.graphics.Bitmap.nativeCreate(Native Method)
android.graphics.Bitmap.createBitmap(Bitmap.java:903)
android.graphics.Bitmap.createBitmap(Bitmap.java:880)
android.graphics.Bitmap.createBitmap(Bitmap.java:847)
org.islq.board.BoardView.void onSizeChanged(int,int,int,int)(Unknown Source)
android.view.View.sizeChange(View.java:15770)
......
我的自定义视图包含以下代码:
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
if (this.background != null) {
this.background = null;
System.gc();
Runtime.getRuntime().gc();
}
this.background = Bitmap.createBitmap(w, h,
Bitmap.Config.ARGB_8888);// throw exception at here
Canvas localCanvas = new Canvas(this.background);
drawBackgroundGrid(localCanvas);
}
此异常仅在“Android 4.4.2,19级”设备上引发。 如何解决?