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

  • Home
  • SEARCH
  • 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 8546867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:08:03+00:00 2026-06-11T13:08:03+00:00

When i run the application and touch the bitmap sometimes appliaction craches Here is

  • 0

When i run the application and touch the bitmap sometimes appliaction craches

Here is the error:

at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
at java.util.ArrayList.get(ArrayList.java:304)
at com.example.Game.GFXSurface$GameSurface.run(GFXSurface.java:135)
at java.lang.Thread.run(Thread.java:864)

And the code where it craches and if i remove balls.remove and balls.add everything works fine but than it won’t generate new ball, and in run method everything works fine with remove and add:

@Override
public boolean onTouch(View v, MotionEvent event) {
    // TODO Auto-generated method stub
    GameSurface gamesurface = new GameSurface(this);
    x = event.getX();
    y = event.getY();
    Bitmap ball = BitmapFactory.decodeResource(getResources(),
            R.drawable.ic_launcher);
    for (int i = 0; i < 4; i++)
        if (ourSurfaceView.MouseOnDot(ball) && x >= ballX[i]
                && x <= ballX[i] + 72) {
            balls.remove(i);
            balls.add(i, gamesurface.RandomBall());
            ChangingY[i] = 0;
            if (speed <= 7)
                speed += 0.1;
        }
    return false;
}

here is the method where is balls.get

@Override
        public void run() {

            for (int j = 0; j < 4; j++) {
                balls.add(j, RandomBall());
            }

            while (isRunning) {
                if (!ourHolder.getSurface().isValid())
                    continue;

                Canvas canvas = ourHolder.lockCanvas();
                canvas.drawRGB(02, 02, 150);

                for (int i = 0; i < 4; i++) {
                    ballX[i] = i * 155;
                    canvas.drawBitmap(balls.get(i), ballX[i], ChangingY[i],
                            null);
                    if (ChangingY[i] <= canvas.getHeight()) {
                        ChangingY[i] += 1 * speed;
                    } else if (ChangingY[i] > canvas.getHeight()) {
                        ChangingY[i] = 0;
                        if (speed <= 5)
                            speed += 0.25;
                        balls.remove(i);
                        balls.add(i, RandomBall());

                    }
                }

                // }

                ourHolder.unlockCanvasAndPost(canvas);
            }
        }
  • 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-11T13:08:04+00:00Added an answer on June 11, 2026 at 1:08 pm

    Error means that index which you use to access ArrayList is bigger than ArrayList size.

    Try instead of for (int i = 0; i < 4; i++) use for (int i = 0; i < balls.size(); i++)

    Or when you use balls.remove(i) check first if i < balls.size

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

Sidebar

Related Questions

I am building an application for the ipod touch that needs to run for
My application will be run on computers with touch screens, operated by police officers
I built and run an iPhone application on iPod Touch 2.2.1 device, got some
I was able to run the Sencha Touch Application with Phonegap on Android Emulator
We're building a touch screen kiosk application that will run on Windows POS Ready
I have a Blackberry application which, when run in some emulators with touch support
When I run my application on iPod touch, I keep my device idle and
I have built a multi-touch application which is based on a Java EE backend
I'm trying to run my application on my old 2nd generation iPod Touch running
I need to run application in every X seconds, so, as far as cron

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.