i checked everywhere i could for the answer. this is basically the problem i have. i declared a array at the class level. i have a text file with x lines of strings. how do i find the number of elements i need for the array
import java.io.*;
import java.util.Scanner;
public class ClockShop
{
private String[] clocks = new String[index()];
private int index() throws FileNotFoundException
{
Scanner file = new Scanner(new File("clocks.txt"));
int i = 0;
while(file.hasNextLine())
{
i++;
file.nextLine();
}
file.close();
return i;
}
}
this is the error im getting:
ClockShop.java:9: unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown
private String[] clocks = new String[index()];