S
S
student_12021-09-18 18:58:16
Java
student_1, 2021-09-18 18:58:16

Why throws ArrayIndexOutOfBoundsException?

I connect to the server to select a fresh file, but when searching for a file, it throws an exception:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0

What could be the problem?

code snippet:
public static FTPFile lastFileModified(FTPFile[] files)
    {
        Date lastMod = files[0].getTimestamp().getTime();
        FTPFile choice = files[0];

        for (FTPFile file : files)
        {
            if (file.getTimestamp().getTime().after(lastMod))
            {
                choice = file;
                lastMod = file.getTimestamp().getTime();
            }
        }
        return choice;
    }

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-09-18
@student_1

Because the files array is empty. It's written.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question