Another way for fixing java.lang.IllegalArgumentException: object is not an instance of declaring class : By modifying the valueOf() as a static method : the error is fixed and this is not an heresy.