Exception in thread "main" java.lang.NegativeArraySizeException: -5 code example

Example: Exception in thread "main" java.lang.NegativeArraySizeException at Main.main(Main.java:21)

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;

public class Main
{
	public static void main(String[] args) {
		 String  line   ; 
    String startTime ;
    String endTime;
    String name ;
     int n=0;
    int[] sumstrttime  = new int[n];
    int[] sumendtime = new int[n-1];
    int[] sum = new int[n];
    int time ;
    int hh;
    int mm;
    int endhh;
    int endmm;
    int meet ;
    StringTokenizer tokens = null;
    String fileName="C";
    try {   
 BufferedReader input = new BufferedReader(new FileReader(fileName) );
 while((line = input.readLine())!=null){
     System.out.println( line );
     StringTokenizer st = new StringTokenizer(  line ," ");
     int s = Integer.parseInt(System.console().readLine());

     if (n>9){
          startTime = tokens.nextToken();
     StringTokenizer start = new StringTokenizer(startTime ,":");
     hh=Integer.parseInt(start.nextToken());
     hh=hh*60;
     mm=Integer.parseInt(start.nextToken());
     
     System.out.println(startTime);
     endTime = tokens.nextToken();
     StringTokenizer end = new StringTokenizer(startTime ,":");
     endhh=Integer.parseInt(end.nextToken());
     endhh=endhh*60;
     endmm=Integer.parseInt(end.nextToken());
     name = tokens.nextToken();
     for(int i = 0; i < n; i++){
         sumstrttime  [i] = hh+mm;
         sumendtime[i] = endhh+endmm;
          sum[i]=sumendtime[i] - sumstrttime[i+1];
          System.out.print("time " + sum[i]);
     }
     
     }
     
  
   
 }
} 
catch(IOException e ){
    System.out.print("not found ");
}
	}
}

Tags:

Java Example