Drag the stack out by using e.printStackTrace() instead. Also, never pull the toString off of the exception's getMessage; it is possible for that to be null.
Once you have the stack it should give you the line number. Since there are several items here that can throw exceptions you need to determine which it is. To me the only one that makes sense is the split method. The array itself would have one result even on an empty string, but if the string is null to start with than you cannot split it.
You can also place a breakpoint on the try and walk it through a debugger to confirm.
Yep, you bet.
You can simplify it as well by converting a collection out of it. Collections can be shuffled, so you could simply convert the array to a list, and then shuffle the list and pull the first item.
PHP Code:
String s = "1;17;22;14;2"; List<String> list = Arrays.asList(s.split(";")); Collections.shuffle(list); System.out.println("Random item: " + list.get(0));