Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9137537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:06:56+00:00 2026-06-17T09:06:56+00:00

I am currently trying to get my head wrapped around imagej, and just trying

  • 0

I am currently trying to get my head wrapped around imagej, and just trying to duplicate an image and spit out the output. The general idea is to get the image, get the pixel array off the image processor, copy it into a new array, and build up a new image from that array.

Now in this, the value of aPixels_org[0] exists, as you can see by the console output. but its still throwing an arrayoutofbounds exception, even with all my checks.

Here is the code… (btw l. is just an logger object, and just a sanity check to check if the array values exist in the if condition below. Do advise if there is a better way, as i am a c++ guy, and am used to checking stuff directly, as java wont allow the if(int){} check)

I am getting the aPixels_org from a function, an dthe aPixels_dup is just created as such

int[] aPixels_dup = new int[iWidth*iHeight];

where iWidth*iHeight is the size of the array needed. I have also tried to generate the size directly with the array.length() option.
The problem code is

System.out.println(">>>>>>>>>>>>>>>>>>>>>." + aPixels_dup[0] +"  " + aPixels_org[0] + "  " + iWidth + "  " + iHeight);
    if(Integer.toString(aPixels_org[0]) != null &&  Integer.toString(aPixels_dup[0]) != null )
    {
        l.info("Arrays exsist");
        System.arraycopy(aPixels_org,0,aPixels_dup,0,iWidth*iHeight);
        l.info("Array Copied");
    }
    else{l.warn("Something is NULL");}
    l.info("");

This is the error

java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at Alpha_.DuplicateCurrentImage(Alpha_.java:64)
at Alpha_.run(Alpha_.java:81)
at ij.IJ.runUserPlugIn(IJ.java:185)
at ij.IJ.runPlugIn(IJ.java:152)
at ij.Executer.runCommand(Executer.java:127)
at ij.Executer.run(Executer.java:64)
at java.lang.Thread.run(Thread.java:679)

Here is the console output

[INFO] % FILE: Alpha_.java % CLASS: Alpha_ % FUNCTION: DuplicateCurrentImage % LINE: 59    % COMMENT: OK % % % TIMESTAMP: 2013-01-17 00:26:55,942
 0  -1393202  466  466
[INFO] % FILE: Alpha_.java % CLASS: Alpha_ % FUNCTION: DuplicateCurrentImage % LINE: 63 % COMMENT: Arrays exsist % % % TIMESTAMP: 2013-01-17 00:26:55,942

Thats the end of my output, and the program crashes with the above error. As you can see, all the 4 values exist in some form or the other. I googled the error and found that the error is

Thrown to indicate that an array has been accessed with an illegal index. The index is either negative or greater than or equal to the size of the array.

Am i missing something obvious here?

RE

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:06:56+00:00Added an answer on June 17, 2026 at 9:06 am

    Both arrays—aPixels_org and aPixels_dup—must have length at least iWidth*iHeight (which is 217156, according to your console output). One (or both) of the arrays must be shorter that that, which is why you are getting the exception. Also be sure that the value of iWidth*iHeight did not increase between the allocation of aPixels_dup and the call to System.arraycopy.

    It would be safer to use Math.min(aPixels_org.length, aPixels_dup.length) as the last argument to System.arraycopy. However, that would hide any length errors in your code. You might want to assert that both arrays have the expected length.

    Also, your checks seem to be meaningless. The fact that an element at index 0 exists in both arrays is kind of irrelevant. Also, Integer.toString(int) never returns null. Here’s a version of your code that does some sensible checks:

    if (aPixels_org != null &&
        aPixels_dup != null &&
        aPixels_org.length == aPixels_dup.length &&
        aPixels_org.length == iWidth*iHeight )
    {
        l.info("Array sizes match");
        System.arraycopy(aPixels_org,0,aPixels_dup,0,iWidth*iHeight);
        l.info("Array Copied");
    }
    else{l.warn("Something is NULL or dimensions are off");}
    l.info("");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to get my head around MUI, and getting some issues with
I am currently trying to get my head around some basic php string functions.
I'm currently trying to get my head around arrays and how to utilise them
I'm currently trying to get my head around noexcept (like almost everyone I avoided
I'm trying to get my head wrapped around tangent space and I'm starting to
I'm currently trying to get my head wrap around Cassandra/thrift with Erlang... I have
Currently trying to get my head round C++11 and have just discovered the auto
I'm currently trying to get my head around the jQuery language. I'm trying to
I'm currently trying to get my head around casting and boxing. As i understand
Trying to get my head around the old C language. Currently on structs and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.