makkuzu
makkuzu

Reputation: 485

Can't start activity get error

The Activity cannot be started I get that error log(red lines):

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

And probably error coming codes are:

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

Upvotes: 0

Views: 252

Answers (2)

Waza_Be
Waza_Be

Reputation: 39564

The 2 relevant lines in your logcat are:

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)

That basically mean that one of your array is not correct and you are looking outside the index.

The only array I can find in your code is:

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

Please check at line 188 of your Picture.Java file and fix the code

Upvotes: 0

Gyonder
Gyonder

Reputation: 3756

You should correct ClrbxPx like this:

 ClrbxPx = new int[orgWidth2 * orgHeight2];

Upvotes: 2

Related Questions