• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unexpected Exception

 
Vivek Alampally
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kindly look at the following program & output , and kindly tell me why it is generating ArrayIndexOutOfBoundsException


Output:
java.lang.ArrayIndexOutOfBoundsException: 1
at TestMain.addName(TestMain.java:40)
at TestMain.getNames(TestMain.java:31)
at TestMain.go(TestMain.java:18)
at TestMain.main(TestMain.java:13)
[Vivek, Santosh, Kathik Reddy, Karthik, Sravan, Bhanu, Shailendra, Rakesh, Vivek]
[Bhanu, Karthik, Kathik Reddy, Rakesh, Santosh, Shailendra, Sravan, Vivek, Vivek]


 
Rob Spoor
Sheriff
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that line with ----- part of your file? Because the line.split will return an array with less than 3 elements if there aren't that many /s in the file.
 
Vivek Alampally
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you talking about the line which is used to underline Names.txt? If yes, there is no such line in Names.txt file. Names.txt file starts with Vivek/02K01A0560/25...........
And, did you notice a thing about output? ( Output is absolutely right, but I am worried about exception ?)
 
Rob Spoor
Sheriff
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you print out the line and the results from splitting?
This will show you where it's going wrong.
 
Vivek Alampally
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I noticed one thing here, when we replace third argument in names.txt file with a string then it is not giving any exception.
 
Vivek Alampally
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry above statement worked only once. Now its not working. I mean it is still giving an exception.
 
Rob Spoor
Sheriff
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what do these two printlns I suggested say?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic