How to resolve Java.lang.numberformatexception: empty string

Solution 1:

Firstly I don't understand why you are taking object type as an input, however to resolve your issue you can do something like this. But I would strongly advice you to change the method signature it is misleading.

public static BigDecimal setValue(Object o) {
    var value = new BigDecimal(0);
    if (o != null) {
        if(o instanceof String) {
            if (((String) o).trim().length()>0) {
                value = new BigDecimal((String) o);
            }
        }
    }
    return value;
}