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 8251215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:09:47+00:00 2026-06-08T00:09:47+00:00

I have this code to create an ArrayList with all the pixel locations where

  • 0

I have this code to create an ArrayList with all the pixel locations where there is actually a pixel (alpha != 0).

The code is as follows:

public ArrayList<Point> getPixels() {
    ArrayList<Point> output = new ArrayList<Point>();
    Image frameImage = img.getCurrentFrame();
    for (int FIx = 0; FIx <= img.getWidth(); FIx++) {
        for (int FIy = 0; FIy <= img.getHeight(); FIy++) {
            if (frameImage.getColor(FIx, FIy).getAlpha() != 0.00f) {//<-- Error
                output.add(new Point(FIx, FIy));
            }
        }
    }

    return output;
}

The loop can complete fine several times, without any error but on a supposedly random time it is ran, it gives the following error:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 32768
    at org.newdawn.slick.Image.getColor(Image.java:1248)
    at com.SourCherry.games.KittySniper.Enemy.Kitten.getPixels(Kitten.java:197)

I have labelled the line mentioned (Kitten.java:197) with a comment.

If anything else is required to help solve this problem, please ask in the comments. Thanks.

  • 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-08T00:09:49+00:00Added an answer on June 8, 2026 at 12:09 am

    This looks like the problem to me:

    for (int FIx = 0; FIx <= img.getWidth(); FIx++) {
        for (int FIy = 0; FIy <= img.getHeight(); FIy++) {
    

    You’re assuming that it’s got pixels in a range that includes getWidth and getHeight. I strongly suspect these are exclusive upper bounds:

    for (int FIx = 0; FIx < img.getWidth(); FIx++) {
        for (int FIy = 0; FIy < img.getHeight(); FIy++) {
    

    So for example, an image with a width of 3 should have valid X values of 0, 1 and 2 – not 3.

    Admittedly this depends on exactly what org.newdawn.slick.Image does, and that’s a class I’m not familiar with – but it’s a reasonable starting point. (It’s a shame that clearly that method doesn’t validate its inputs – it should throw a different exception, but it’s still your programming error.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code in my DataBase Helper: public ArrayList<ArrayList<Object>> getAllRowsAsArrays() { // create
I have this code to create an ATOM feed Dim xmlResult As New StringBuilder
I have this code to create a webapp in my server: import web urls
I have this code which should create a splash image with either no animation
I have this code. This code won't create a file in the Document directory
I have this code working in C#: var request = (HttpWebRequest)WebRequest.Create(https://x.com/service); request.Method = GET;
I have the this code that will create excel file and work sheet then
Currently I have this code var App = Ember.Application.create(); App.user = Ember.Object.create({ people: customers
I have this code in a .html.erb file: <script src=http://connect.facebook.net/en_US/all.js#xfbml=1></script> <script> FB.Event.subscribe('edge.create', function(response) {
I have this webdav code thats creating folders in SharePoint: HttpWebRequest request = (System.Net.HttpWebRequest)HttpWebRequest.Create(folderAddress);

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.