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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:57:25+00:00 2026-05-29T04:57:25+00:00

**Have it working now. I forgot to populate the Array List. How embarrassing. I’m

  • 0

**Have it working now. I forgot to populate the Array List. How embarrassing.

I’m getting this error:

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:604)
at java.util.ArrayList.set(ArrayList.java:397)
at Netbooks.Calculations.topTen(Calculations.java:93)
at Netbooks.Test.main(Test.java:33)
Java Result: 1

The error refers to this specific line:
aveList.set(maxBook, 0.0);

Which looks correct to me, but then again I’m new and am probably wrong…

I’m going to add some more code so you guys can check the size of the array and whatnot, hopefully catch something I didn’t.

Here is the method that has the error:

    public List<String> topTen() throws IOException {
    Books books = new Books();
    List<String> bookList = books.readBooks();

    List<String> topList = new ArrayList<String>(10);
    List<Double> aveList = new ArrayList<Double>();

    for (int i = 0; i < 10; i++) {
        double maxRating = 0.0;
        int maxBook = 0;

        for (int j = 0; j < aveList.size(); j++) {
            if (maxRating < aveList.get(j)) {
                maxRating =  aveList.get(j);
                maxBook = j;
            }
        }
        topList.add(bookList.get(maxBook));
        aveList.set(maxBook, 0.0);
    }

    return topList;
}

Here is where the ArrayList “aveList” is originally generated:

public List<Double> aveRatings() throws IOException {
    Books books = new Books();
    Ratings ratings = new Ratings();
    PureRatings pureRatings = new PureRatings();

    int numBooks = books.readBooks().size();
    int numCust = ratings.readCustomers().size();
    List<List<Integer>> pureRatingsList = pureRatings.parseRatingsFile();
    List<Double> aveRatings = new ArrayList<Double>();

    for (int j = 0; j < numBooks; j++) {
        double sum = 0;
        double counter = 0;

        for (int i = 0; i < numCust; i++) {
            if (pureRatingsList.get(i).get(j) != 0) {
                sum = sum + pureRatingsList.get(i).get(j);
            } else {
                counter++;//Increase counter.
            }
        }
        if (counter == numCust) {
            aveRatings.add(0.0);
        } else {
            aveRatings.add((sum) / (numCust - counter));
        }
    }
    return aveRatings;
}

I’ve been at it for a while now and can’t seem to find out what’s wrong. Any help would be appreciated.

  • 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-05-29T04:57:30+00:00Added an answer on May 29, 2026 at 4:57 am

    It doesn’t help that you’re giving methods the same name as variables, but basically your topTen method isn’t calling aveRatings() – it’s just creating an empty list:

    List<Double> aveList = new ArrayList<Double>();
    

    It’s then trying to set values in that list:

    aveList.set(maxBook, 0.0);
    

    maxBook will be 0 even if aveList is completely empty.

    Did you mean to write:

    List<Double> aveList = aveRatings();
    

    ? Note that I haven’t looked at the details of the rest of the code – I’ve only looked for why you’re getting your immediate exception.

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

Sidebar

Related Questions

I have this regex working but now need to allow numbers without the decimal
I have been working on this for 24 hours now, trying to optimize it.
I have been working on this problem for 2 days now and it's an
I have been working on this problem for a while now. I am trying
So I have been working on this project for a short while now. I
I'm working now together with others in a grails project. I have to write
The Zend Framework based site I have been working on is now being migrated
I have been working on a Windows Mobile app for a little while now
I have been working with resource files for a while now and I was
I have been working as a native C++ programmer for last few years. Now

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.