'java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1 error is being received and cannot confirm why

I understand that this error message indicates that I am trying to access a particular element in an array via index which is not present, or it is an invalid element trying to access outside of the length in a String. However, I have not been able to confirm where exactly this is occurring in my code with the information provided from error message:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
    at Week3.luis_ramirez_GamesReport.readWrite(luis_ramirez_GamesReport.java:63)
    at Week3.luis_ramirez_GamesReport.main(luis_ramirez_GamesReport.java:30) 

I have reviewed previous questions posted about this but my code formats don't seem similar to others that have been posted. I have attempted to change the order of my output but since the desired output is already printing, I stopped doing so. I have also attempted to change line

String[] ints_only = Arrays.copyOfRange(record, 1, record.length);

to a value of 0 instead of 1.

Here is my code:

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;


public class luis_ramirez_GamesReport {


    public static void main(String[] args) throws IOException
    {
        {
            File fileName = new File("/Users/luisramirez/eclipse-workspace/GameScores.txt");
              readWrite(fileName);
              addGamer(fileName, "Jimmy", "189", "190", "197", "199", "198", "193", "199", "199", "188", "196");
              readWrite2(fileName);}
          }
        private static void readWrite(File fileName) throws IOException {
            

        if (fileName.exists())
        {
            BufferedReader br = null;
            String line = "";
            String csvSplitBy = ",";
            int recordCount = 0;
            //String number ="167";
            //int result = Integer.parseInt(number);
            br = new BufferedReader(new FileReader(fileName));
        
        System.out.println("-----------------------------------------------------------------------------------------------");
        System.out.println("Games Report");
        System.out.println("-----------------------------------------------------------------------------------------------");
        System.out.println("Gamer    1       2       3       4       5       6       7       8       9       10     Total");
        System.out.println("-----------------------------------------------------------------------------------------------");
        
        while ((line = br.readLine()) != null)
        {
        String[] record = line.split(csvSplitBy);
        String[] ints_only = Arrays.copyOfRange(record, 1, record.length);
        List<Integer> recordAsInts = Arrays.stream(ints_only)
            .map(str -> str.strip())
            .map(Integer::parseInt)
            .collect(Collectors.toList());
        int sum = recordAsInts.stream().reduce(Integer::sum).orElse(0);
        System.out.println(record[0] + "\t"
            + record[1] + (record[1].length() > 7 ? "\t" : "\t")
            + record[2] + (record[2].length() > 7 ? "\t" : "\t")
            + record[3] + (record[3].length() > 7 ? "\t" : "\t")
            + record[4] + (record[4].length() > 7 ? "\t" : "\t")
            + record[5] + (record[5].length() > 7 ? "\t" : "\t")
            + record[6] + (record[6].length() > 7 ? "\t" : "\t")
            + record[7] + (record[7].length() > 7 ? "\t" : "\t")
            + record[8] + (record[8].length() > 7 ? "\t" : "\t")
            + record[9] + (record[9].length() > 7 ? "\t" : "\t")
            + record[10] + (record[10].length() > 7 ? "\t" : "\t")
            + sum);
            recordCount++;
                
        }
        
        System.out.println("----------------------------------------------------------------------------------------------");
        System.out.printf("# of Gamers: %d%n",recordCount);
        System.out.println("Top Gamer: ");
        System.out.println("----------------------------------------------------------------------------------------------");
            br.close();
        }

Here is a link to an image of my output:

Output

Here is line 30: readWrite(fileName);

Here is line 63: + record[1] + (record[1].length() > 7 ? "\t" : "\t")



Solution 1:[1]

I tried your code and it worked fine, actually i changed the path of the folder and added some other lines to make others players.

i think your problem is that you are not using the absolute path

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Azer El Hasnaoui