活动无法启动我收到错误日志(红线):
03-03 12:29:50.492: E/AndroidRuntime(24207): FATAL EXCEPTION: main
03-03 12:29:50.492: E/AndroidRuntime(24207): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.makkuzu.hello/com.makkuzu.hello.Picture}: java.lang.ArrayIndexOutOfBoundsException
03-03 12:29:50.492: E/AndroidRuntime(24207): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
03-03 12:29:50.492: E/AndroidRuntime(24207): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
03-03 12:29:50.492: E/AndroidRuntime(24207): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-03 12:29:50.492: E/AndroidRuntime(24207): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
03-03 12:29:50.492: E/AndroidRuntime(24207): at android.os.Handler.dispatchMessage(Handler.java:99)
03-03 12:29:50.492: E/AndroidRuntime(24207): at android.os.Looper.loop(Looper.java:130)
03-03 12:29:50.492: E/AndroidRuntime(24207): at android.app.ActivityThread.main(ActivityThread.java:3693)
03-03 12:29:50.492: E/AndroidRuntime(24207): at java.lang.reflect.Method.invokeNative(Native Method)
03-03 12:29:50.492: E/AndroidRuntime(24207): at java.lang.reflect.Method.invoke(Method.java:507)
03-03 12:29:50.492: E/AndroidRuntime(24207): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
03-03 12:29:50.492: E/AndroidRuntime(24207): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
03-03 12:29:50.492: E/AndroidRuntime(24207): at dalvik.system.NativeStart.main(Native Method)
03-03 12:29:50.492: E/AndroidRuntime(24207): Caused by: java.lang.ArrayIndexOutOfBoundsException
03-03 12:29:50.492: E/AndroidRuntime(24207): at android.graphics.Bitmap.checkPixelsAccess(Bitmap.java:838)
03-03 12:29:50.492: E/AndroidRuntime(24207): at android.graphics.Bitmap.getPixels(Bitmap.java:780)
03-03 12:29:50.492: E/AndroidRuntime(24207): at com.makkuzu.hello.Picture.onCreate(Picture.java:188)
03-03 12:29:50.492: E/AndroidRuntime(24207): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-03 12:29:50.492: E/AndroidRuntime(24207): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
03-03 12:29:50.492: E/AndroidRuntime(24207): ... 11 more
并且可能出现的错误代码是:
colorbox = BitmapFactory.decodeResource(getResources(),
R.drawable.color_picker);
b = BitmapFactory.decodeResource(getResources(), R.drawable.picker);
orgWidth2 = colorbox.getWidth();
orgHeight2 = colorbox.getHeight();
orgWidth = oldBitmap.getWidth();
orgHeight = oldBitmap.getHeight();
myColors = Bitmap.createBitmap(orgWidth2, orgHeight2,
Bitmap.Config.ARGB_8888);
newBitmap = Bitmap.createBitmap(
orgWidth, orgHeight, Bitmap.Config.ARGB_8888);
pixels=pixels1=pixels2=pixels3=pixels4 = new int[orgWidth * orgHeight];
ClrbxPx = new int[orgWidth * orgHeight];
oldBitmap.getPixels(pixels, 0, orgWidth, 0, 0, orgWidth, orgHeight);
newBitmap.setPixels(pixels, 0, orgWidth, 0, 0, orgWidth, orgHeight);
colorbox.getPixels(ClrbxPx, 0, orgWidth2, 0, 0, orgWidth2, orgHeight2);
myColors.setPixels(ClrbxPx, 0, orgWidth2, 0, 0, orgWidth2, orgHeight2);
myFrame = BitmapFactory
.decodeResource(getResources(), R.drawable.frame);
canvas = new Canvas(newBitmap);
canvas.drawBitmap(myFrame, 1, 1, null);