Your first problem is that the code you've given reads only the first number forever: you never change inputString. Strictly speaking, you can't change it--Strings are immutable--but you could at least replace it with another String that's shorter. If you're just starting out, try the substring() method; if you're feeling fancy, you could do it the correct way, which is by using a StringBuffer.
I have no idea how you got a runtime error with the code you've given; I ran it on my JVM and it just kept reading the first number for ever and ever. But in this context, -1 should indicate either that you've reached end-of-file or that inputString.indexOf(loc) can't find the loc substring.
Whenever you see a -1, you should check the API to see what values your function calls might be returning. In general, beginning
Java programmers should always code with the API right in front of them at all times.