I have a code where I need to call number of Jobs as public static integers from Size.txt file as follows:
public class GetJobs {
public static int Jobs = valueN(), inp = 4;
public static void main(String[] args)throws IOException{
........................
}
public static int valueN(){
int n;
File file = new File("C:\\Data\\Size.txt");
String[] eachLine ;
int[] MN = new int [inp];
try{
Scanner input = new Scanner(file);
eachLine = input.nextLine().split("\\s+");
for(int j=0; j<inp;j++){
MN[j]=Integer.parseInt(eachLine[j]);
}
System.out.print("\n");
input.close();
}
catch(Exception e){
e.printStackTrace();
}
n=MN[0];
return n;
}
in Size.txt file the number of Jobs is the first element, the problem is I get an error when I run it. What is the problem?
the error is: Exception in thread "main" java.lang.ExceptionInInitializerError Caused by: java.lang.ArrayIndexOutOfBoundsException: 0