0

I was wondering if anyone could help me out with this exception I've been getting.

I have a custom class/object named MindsparkPartnerCode with two variables named ieFFCode & chromeCode.

I would like for my Selenium Java program to create an array of MindsparkPartnerCode objects, read from a CSV file, and then store the values read from the first column of that CSV file into the ieFFCode for the first object the the array, and so on, until it reaches the first blank line.

However, each time I run the program, I get an ArrayIndexOutOfBoundsException at the line record.setIEFFCode(chunks[0]);

Could anyone tell me what I'm doing wrong? I'm using old code from a co-worker of mine, which is why I'm not using an "index" for the Array. Though I'd be willing to use that if it would make the code more readable.

        List<MindsparkPartnerCode> records = new ArrayList<MindsparkPartnerCode>();

        FileReader r = new FileReader(
                "C:\\DailyLocalGuidePartnerCode.csv");
        BufferedReader bfr = new BufferedReader(r);

        String line = null;
        try {
            while ((line = bfr.readLine()) != null) {
                if (StringUtils.isBlank(line))
                    continue;

                System.out.println(line);
                String[] chunks = line.split(",");
                MindsparkPartnerCode record = new MindsparkPartnerCode();

                record.setIEFFCode(chunks[0]);
                records.add(record);
            }
        } finally {
            bfr.close();
            r.close();  
        }
  • I am having trouble finding the Selenium code in this question. – user246 Dec 2 '14 at 4:04
0

line contains nothing but commas. That causes line.split to return a zero-length array. Since the array is empty, chunks[0] causes an ArrayOutOfBoundsException.

  • i included my answer up above. – kevin Dec 2 '14 at 10:12
0
        //create a list/array of the partner codes found within the source file
        List<MindsparkPartnerCode> records = new ArrayList<MindsparkPartnerCode>();
        //set the location of the file and create a read buffer
        FileReader r = new FileReader("C:\\DailyLocalGuidePartnerCode.csv");
        BufferedReader bfr = new BufferedReader(r);

        String line = null;
        try {
            while ((line = bfr.readLine()) != null) {
                if (StringUtils.contains(line, ",,,"))
                    continue;
                //System.out.println(line); //for debugging
                String[] chunks = line.split(",");
                MindsparkPartnerCode record = new MindsparkPartnerCode();
                record.setIEFFCode(chunks[0]);
                records.add(record);
                //System.out.println(chunks); //for debugging
                System.out.println("This is the current record's IE/FF Code: " + record.getIEFFCode());
                driver.get(testURL + record.getIEFFCode());
                //find the URL for the mindpark javascript implementation
                //String pageSourceURL = driver.findElement(By.("//meta[@name='keywords']")).getAttribute("content");
                //System.out.println("When using that IE/FF code in a Chrome browser, the partner code is changed to this:" + 
                    //driver.get(testURL + record.getIEFFCode()));
            }
        } finally {
            bfr.close();
            r.close();
            //System.out.println(records); //for debugging
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.