I made a program which reads a text file which contains tweets. This text file is 16MB so it's really large. My program reads it line by line and adds words to an ArrayList. While doing this, I got an ArrayIndexOutOfBoundsException. I debugged my code to part where it throws exception. I noticed that, code keeps running after throwing exception and adds words to ArrayList.
java.lang.ArrayIndexOutOfBoundsException: 0
at Test.main(Test.java:39)
java.lang.ArrayIndexOutOfBoundsException: 0
at Test.main(Test.java:39)
java.lang.ArrayIndexOutOfBoundsException: 0
at Test.main(Test.java:39)
java.lang.ArrayIndexOutOfBoundsException: 0
at Test.main(Test.java:39)
#Jobs: 272
#Job: 269
#jobs: 225
#TweetMyJOBS: 223
#job: 155
That's how it looks on console. After multiple exceptions, my program runs and displays a result. Result is also wrong.For example, first one should be #Jobs: 4251. Does anybody have any idea why would it throw exception then keeps running?
here is the code:
try
{
line = reader.readLine();
// scan = new Scanner(textinput);
while (line != null)
{
String[] splitted = line.split("#"); // Line splitted according to "#".
for (int x = 1; x < splitted.length; x++)
{
String[] temp = splitted[x].split(" "); // String splitted with space and first word is hashtag.
try
{
//Line 39 is here.
hashtags.add(temp[0]); // hashtag added to ArrayList.
} catch (ArrayIndexOutOfBoundsException e)
{
e.printStackTrace();
}
}
line = reader.readLine();
linenum++;
}
} catch (FileNotFoundException e1)
{
e1.printStackTrace();
}