0

アクティビティを開始できませんそのエラーログ(赤い線)が表示されます:

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);
4

2 に答える 2

2

次のように ClrbxPx を修正する必要があります。

 ClrbxPx = new int[orgWidth2 * orgHeight2];
于 2013-03-03T10:57:31.100 に答える
0

logcat の関連する 2 行は次のとおりです。

03-03 12:29:50.492: E/AndroidRuntime(24207): Caused by: java.lang.ArrayIndexOutOfBoundsException
03-03 12:29:50.492: E/AndroidRuntime(24207):    at com.makkuzu.hello.Picture.onCreate(Picture.java:188)

これは基本的に、配列の 1 つが正しくなく、インデックスの外を見ていることを意味します。

コードで見つけることができる唯一の配列は次のとおりです。

 pixels=pixels1=pixels2=pixels3=pixels4 = new int[orgWidth * orgHeight];
    ClrbxPx = new int[orgWidth * orgHeight];

Picture.Java ファイルの 188 行目を確認し、コードを修正してください。

于 2013-03-03T11:01:57.190 に答える