Here is another advise. Never ever cast to String in Java: e.g. String foo = (String)someObject; Always use the toString method, because a cast can fail, toString never fails (except it was implemented by a fool).