I am trying to calculate the overall time of an album.
The user enters the track length (double) in format mm.ss .
Then convert this in a String so I can calculate min and sec separately.

public void overallRunningTime()
    {
        int min = 0;
        int sec = 0;

        for(int i = 0; i < album.size(); i++)
        {
            double songLength = album.get(i).getTrackLength();

            String trackLength = String.valueOf(songLength);
            String[] songLengthSplit = trackLength.split(".");



            min = Integer.valueOf(songLengthSplit[0]);
            sec = Integer.valueOf(songLengthSplit[1]);


            if(Integer.parseInt(songLengthSplit[1]) > 60)
            {
                sec = Integer.valueOf(songLengthSplit[1]) % 60;
                min = Integer.valueOf(songLengthSplit[1]) / 60;
            }else
            {
                sec = Integer.valueOf(songLengthSplit[1]);
            }

            System.out.println("Seconds: " + sec);
            System.out.println("Minutes: " + min);

//          overallTime += songLength;
        }



        System.out.print("The overall time is: " + overallTime);
    }

I get an java.lang.ArrayIndexOutOfBoundsException: 0

at this line min = Integer.valueOf(songLengthSplit[0]);

it would appear there is a problem with your array, that there is no array.
or, at least, there are no elements. have you tried printing the value of trackLength before creating the array?
have you checked the number of elements your array has?

I agree it's unusual for even the first element (index 0) not to be there, but still..

It seems that the trackLength its printed right.

While the array songLengthSplit it seems to be empty.

Using delimeter to escape special characters like . -> String deimeter = "\."

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.