Your String is:
St. Joseph, MO +39.76580 -94.85060
You're splitting it on the tab locations, which there are none in that line. Your array, therefore is of length 1.
tokens[0] = St. Joseph, MO +39.76580 -94.85060
tokens[1] // doesn't exist.
Additionally the input you've provided is also not formatted in a tabular way:
St. Joseph, MO +39.76580 -94.85060
Shanghai,China +31.23300 +121.45000
Kansas_City,KS +39.11780 -94.64000
Notice the last line isn't properly lined up with the others? They would be if you were using hard tabs. Make sure you're not using spaces in lieu of tabs but are actually using the tab button (or equivalent character if data is formatted programmatically).
I recreated the entire project from your own code and got the same error you did. I deleted the spaces and replaced them with actual Tab characters and it works fine.
EDIT After the data works it doesn't print
This is a simple fix. You're calling the toString()
method but that does you no good when you don't do anything with the String value returned to you.
Just make it:
System.out.println(loc.tooString());