0

I am running a code as follows:

java -cp dream.jar:. pro.dr16.Interval ".*.gz" ./name/ flagfold 2,3 
[0, 2]
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at projects.dream2016.Interval.main(SpecificOrConserved2Interval.java:101)    

and the actual code looks like this

 public static void main(String[] args) throws FileNotFoundException, IOException {
            FilenameFilter filter = new RegExFilenameFilter("", Directory.FORBIDDEN, true, args[0] );
            String[] fName = new File( args[1] ).list(filter);
            String[] s = args[2].split(",");
            int[] cols = new int[s.length];
            for( int i = 0; i < cols.length; i++ ) {
                    cols[i] = Integer.parseInt( s[i] );
            }

I am new to extensive java code , any help/suggestion would be great.

AishwaryaKulkarni
  • 774
  • 1
  • 8
  • 19
  • What is line 101? An ArrayIndexOutOfBounds exception indicates that you tried to access a position in the array that does not exist. In this particular case, you tried to get something at index 0 when the array is empty. – Roddy of the Frozen Peas Oct 06 '17 at 15:36
  • 2
    "so I am unable to deduce what exactly is going on in here" - well, what happened when you stepped through in the debugger? – Jon Skeet Oct 06 '17 at 15:36
  • 1
    You sre splitting `args[2]` by `,`, but the only parameter that has a `,` is `args[3]`. Have you checked whether `args[2]` is what you think it is? – tobias_k Oct 06 '17 at 15:38
  • @tobias_k that was my first hunch and when I keep that argument in second position, I get an error "[0, 2] Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0" – AishwaryaKulkarni Oct 06 '17 at 15:39
  • @RoddyoftheFrozenPeas the line 101 is something like this "if( line[0].charAt(0) == '[' ) {" – AishwaryaKulkarni Oct 06 '17 at 15:41

0 Answers0