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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:01:07+00:00 2026-05-31T19:01:07+00:00

I am trying to figure out why I get this error. My code is

  • 0

I am trying to figure out why I get this error. My code is as follows:

 ArrayList lowestQuant = new ArrayList();
    for (int i = 0; i < aRes1.size(); i++) {
        int var = Math.min(casesQuant.get(i), mainboardQuant.get(i));
        int var2 = Math.min(var, cpuQuant.get(i));
        int var3 = Math.min(var2, ramQuant.get(i));
        int var4 = Math.min(var3, graphicsQuant.get(i));
        lowestQuant.add(var4);
        System.out.println(aRes1.get(i) +" quantity: "+lowestQuant.get(i));
    }

aRes1 is an Array List of computer systems with a length of 8 computer systems.

I need to find the component with the lowest quantity in every computer system, hence the Math.min and all the ArrayList-index look-ups.
This code should provide the component with the lowest quantity and it does! But somehow it stops before reaching the 8th computer system. It works perfectly with the first 7.
Can anyone tell me what the problem is?
I’ve looked a lot of these errors up and tried to set i=1 and .size()-1/+1 nothing helps.

Thanks in advance!
Error:

 Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 7, Size: 7
            at java.util.ArrayList.RangeCheck(ArrayList.java:547)
            at java.util.ArrayList.get(ArrayList.java:322)
            at databasen.Database.ComputerSystems(Database.java:242)
            at databasen.Database.menuLVL1(Database.java:70)
            at databasen.Database.mainMenu(Database.java:61)
            at databasen.Database.main(Database.java:37)
    Java Result: 1

To clarify : All the array lists used are of the same length because they are made from a database. Here are some more code so you can see how the array lists are made ::

ArrayList aRes1 = new ArrayList();
        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery("SELECT catchyname FROM computersystems");
        System.out.printf("Computer sytems:\n");
        while (rs.next()) {
            String answer = rs.getString("catchyname");
            aRes1.add(answer);
        }

        // Cases
        ArrayList aRes2 = new ArrayList();
        rs = st.executeQuery("SELECT cases FROM computersystems");
        while (rs.next()) {
            String answer = rs.getString("cases");
            aRes2.add(answer);
        }
        ArrayList<Integer> casesQuant = new ArrayList<Integer>();
        for (int i=0;i<aRes2.size();i++){
            ResultSet rs2 = st.executeQuery("SELECT currentquantity FROM components "
                    + "WHERE name ="+"'"+aRes2.get(i)+"'");
            while (rs2.next()) {
                int answer2 = rs2.getInt("currentquantity");
                casesQuant.add(answer2);
            }
        }
  • 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-31T19:01:08+00:00Added an answer on May 31, 2026 at 7:01 pm

    Any one of the Array Lists has 7 elements . Try checking line number 547 and 322 . you will get an idea which one .

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

Sidebar

Related Questions

Can't seem to figure this out, see code below. Trying to make a GET
Bah, vbscript. I'm trying to figure out how to get this statement to work:
I've been trying to figure this out and can't seem to get it. Here
I'm trying to figure out how to get the size of an installed app.
I've been struggling for several hours trying to figure out how to get this
I wrote this code and I am trying to figure out what I have
I am trying to figure out the cause of this error it occurs on
I'm going crazy trying to figure out this error message that has no obvious
I`m trying to figure out how to get serial and key attributes set for
I'm trying to figure out how to get the users information after validating via

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.