Example usage for java.lang NumberFormatException getMessage

List of usage examples for java.lang NumberFormatException getMessage

Introduction

In this page you can find the example usage for java.lang NumberFormatException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.stackmob.example.geopoints.WriteGeo.java

@Override
public ResponseToProcess execute(ProcessedAPIRequest request, SDKServiceProvider serviceProvider) {
    LoggerService logger = serviceProvider.getLoggerService(WriteGeo.class);
    Map<String, SMObject> feedback = new HashMap<String, SMObject>();
    Map<String, String> errMap = new HashMap<String, String>();

    String user = "";
    String latitude = "";
    String longitude = "";

    JSONParser parser = new JSONParser();
    try {/*from w w w  . j  a  v  a  2  s .c  om*/
        Object obj = parser.parse(request.getBody());
        JSONObject jsonObject = (JSONObject) obj;
        user = (String) jsonObject.get("user_name");
        latitude = (String) jsonObject.get("Latitude");
        longitude = (String) jsonObject.get("Longitude");
    } catch (ParseException pe) {
        logger.error(pe.getMessage(), pe);
        return Util.badRequestResponse(errMap, pe.getMessage());
    }

    if (Util.hasNulls(user, latitude, longitude)) {
        return Util.badRequestResponse(errMap, "Please fill in all parameters correctly");
    }

    DataService ds = serviceProvider.getDataService();
    List<SMUpdate> update = new ArrayList<SMUpdate>();
    Map<String, SMValue> geoPoint = new HashMap<String, SMValue>();
    SMObject result;

    try {
        geoPoint.put("lat", new SMDouble(Double.parseDouble(latitude)));
        geoPoint.put("lon", new SMDouble(Double.parseDouble(longitude)));
        update.add(new SMSet("position", new SMObject(geoPoint)));
    } catch (NumberFormatException nfe) {
        logger.error(nfe.getMessage(), nfe);
        return Util.badRequestResponse(errMap, nfe.getMessage());
    }

    try {
        result = ds.updateObject("user", new SMString(user), update);
        feedback.put("Updated object", result);
    } catch (InvalidSchemaException ise) {
        return Util.internalErrorResponse("invalid_schema", ise, errMap); // http 500 - internal server error
    } catch (DatastoreException dse) {
        return Util.internalErrorResponse("datastore_exception", dse, errMap); // http 500 - internal server error
    }

    return new ResponseToProcess(HttpURLConnection.HTTP_OK, feedback);
}

From source file:com.dngames.mobilewebcam.PhotoSettings.java

public static int getEditInt(Context c, SharedPreferences prefs, String name, int d)
        throws NumberFormatException {
    int i = 0;//from  ww w  . ja v  a 2 s.  co  m
    try {
        i = getEditInt(prefs, name, d);
    } catch (NumberFormatException e) {
        String msg = e.toString();
        if (e.getMessage() != null)
            msg = e.getMessage();
        if (MobileWebCam.gIsRunning) {
            try {
                Toast.makeText(c, msg, Toast.LENGTH_LONG).show();
            } catch (RuntimeException er) {
                er.printStackTrace();
            }
        } else
            MobileWebCam.LogE(msg);
    }
    return i;
}

From source file:com.dngames.mobilewebcam.PhotoSettings.java

public static float getEditFloat(Context c, SharedPreferences prefs, String name, float d)
        throws NumberFormatException {
    float f = 0.0f;
    try {/*from w  ww . j a v  a 2s .co  m*/
        f = getEditFloat(prefs, name, d);
    } catch (NumberFormatException e) {
        String msg = e.toString();
        if (e.getMessage() != null)
            msg = e.getMessage();
        if (MobileWebCam.gIsRunning) {
            try {
                Toast.makeText(c, msg, Toast.LENGTH_LONG).show();
            } catch (RuntimeException er) {
                er.printStackTrace();
            }
        } else
            MobileWebCam.LogE(msg);
    }
    return f;
}

From source file:gda.device.scannable.DummyMultiElementScannable.java

@Override
public String checkPositionValid(Object position) {
    try {//from   w  w  w. ja v  a2 s.  c o m
        if (position instanceof double[] || position instanceof Double[] || position instanceof PyFloat[]) {
            if (Array.getLength(position) == this.currentPosition.length) {
                return null;
            }
        } else if (position instanceof PyArray) {
            if (((PyArray) position).__len__() == this.currentPosition.length) {
                return null;
            }
        } else if (position instanceof PyList) {
            if (((PyList) position).__len__() == this.currentPosition.length) {
                return null;
            }
        } else if (position instanceof Number && this.currentPosition.length == 1) {
            return null;
        }
        return "position must be an array of doubles of the correct length";
    } catch (NumberFormatException e) {
        return e.getMessage();
    }
}

From source file:de.dominikschadow.duke.encounters.validators.SearchFilterValidator.java

@Override
public void validate(Object target, Errors errors) {
    validator.validate(target, errors);/*ww w  . j  ava2s. c  o  m*/

    SearchFilter filter = (SearchFilter) target;

    errors = validateBaseData(filter.getEvent(), filter.getLocation(), filter.getCountry(), errors);

    if (securityValidationService.hasXssPayload(filter.getYear())) {
        fireXssEvent();
        errors.rejectValue("year", Constants.XSS_ERROR_CODE);
    } else if (securityValidationService.hasSqlIPayload(filter.getYear())) {
        fireSqlIEvent();
        errors.rejectValue("year", Constants.SQLI_ERROR_CODE);
    } else if (!Strings.isNullOrEmpty(filter.getYear())) {
        try {
            int year = Integer.parseInt(filter.getYear());

            if (year < 1995) {
                logger.info(SecurityMarkers.SECURITY_FAILURE, "Requested {} as event year - possible typo",
                        filter.getYear());
                errors.rejectValue("year", Constants.INVALID_YEAR_ERROR_CODE);
            }
        } catch (NumberFormatException ex) {
            logger.error(ex.getMessage(), ex);
            errors.rejectValue("year", Constants.INVALID_YEAR_ERROR_CODE);
        }
    }

    try {
        Likelihood.fromString(filter.getLikelihood());
    } catch (IllegalArgumentException ex) {
        logger.info(SecurityMarkers.SECURITY_FAILURE, "Requested {} as likelihood - out of configured range",
                filter.getLikelihood());
        fireInvalidValueEvent();
        errors.rejectValue("likelihood", Constants.ATTACK_ERROR_CODE);
    }

    if (filter.getConfirmations() < 0 || filter.getConfirmations() > 10) {
        logger.info(SecurityMarkers.SECURITY_FAILURE, "Requested {} confirmations - out of configured range",
                filter.getConfirmations());
        fireInvalidValueEvent();
        errors.rejectValue("confirmations", Constants.ATTACK_ERROR_CODE);
    }
}

From source file:com.nokia.example.lwuit.rlinks.network.operation.LinksLoadOperation.java

/**
 * Parse a JSON representation of Reddit links into a Vector
 * of RedditLink objects.//from   ww w.ja va  2  s. co  m
 *
 * @param linksJson The JSON response from the server
 */
private void parseLinks(String linksJson) {
    JSONObject jsonResponse;
    JSONArray jsonItems;
    try {
        try {
            jsonResponse = new JSONObject(linksJson);
        } catch (NumberFormatException nfe) {
            System.out.println("NFE: " + nfe.getMessage());
            return;
        }
        jsonItems = jsonResponse.getJSONObject("data").getJSONArray("children");
    } catch (JSONException e) {
        System.out.println("Could not populate from JSON data: " + e.getMessage());
        return;
    }

    Vector links = new Vector();
    int numItems = jsonItems.length();
    if (numItems > 0) {
        LinkThing item;
        JSONObject jsonObj;
        for (int i = 0; i < numItems; i++) {
            try {
                jsonObj = jsonItems.getJSONObject(i).getJSONObject("data");
                item = LinkThing.fromJson(jsonObj);
                links.addElement(item);
            } catch (JSONException e) {
                System.out.println("Could not parse JSON object: " + e.getMessage());
            }
        }
    }

    finished = true;
    linkListener.linksReceived(links);
}

From source file:de.thorstenberger.examServer.webapp.action.IncreaseTimeExtensionAction.java

@Override
public ActionForward execute(final ActionMapping mapping, final ActionForm form,
        final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final ActionMessages errors = new ActionMessages();

    long taskId;/*from w ww .  j  a v a 2 s. com*/
    try {
        taskId = Long.parseLong(request.getParameter("taskId"));
    } catch (final NumberFormatException e) {
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("misc.error", e.getMessage()));
        saveErrors(request, errors);
        return mapping.findForward("noSelection");
    }
    final String userId = request.getParameter("userId");

    final TaskletContainer container = (TaskletContainer) getBean("TaskletContainer");

    final Tasklet tasklet = container.getTasklet(taskId, userId);
    if (tasklet instanceof ComplexTasklet) {
        final ComplexTasklet ct = (ComplexTasklet) tasklet;
        final Try activeTry = ct.getActiveTry();
        // increase time by 5 minutes
        // TODO make configurable
        activeTry.setTimeExtension(activeTry.getTimeExtension() + 5 * 60 * 1000);
        container.storeTasklet(tasklet);

        log.info(String.format("Increased time for student '%s' by 5min.", userId));

    }
    return mapping.findForward("success");
}

From source file:com.nokia.example.rlinks.network.operation.LinksLoadOperation.java

/**
 * Parse a JSON representation of Reddit links into a Vector
 * of RedditLink objects./*from  w ww .  j a v a 2s . c  o m*/
 *
 * @param linksJson The JSON response from the server
 */
private void parseLinks(String linksJson) {
    JSONObject jsonResponse;
    JSONArray jsonItems;
    try {
        try {
            jsonResponse = new JSONObject(linksJson);
        } catch (NumberFormatException nfe) {
            System.out.println("NFE: " + nfe.getMessage());
            return;
        }
        jsonItems = jsonResponse.getJSONObject("data").getJSONArray("children");
    } catch (JSONException e) {
        System.out.println("Could not populate from JSON data: " + e.getMessage());
        return;
    }

    Vector links = new Vector();
    int numItems = jsonItems.length();

    if (numItems > 0) {
        LinkThing item;
        JSONObject jsonObj;
        for (int i = 0; i < numItems; i++) {
            try {
                jsonObj = jsonItems.getJSONObject(i).getJSONObject("data");
                item = LinkThing.fromJson(jsonObj);
                links.addElement(item);
            } catch (JSONException e) {
                System.out.println("Could not parse JSON object: " + e.getMessage());
            }
        }
    }

    finished = true;
    linkListener.linksReceived(links);
}

From source file:example.TableExample.java

private void insertRow(ChaincodeStub stub, String[] args, boolean update) {

    int fieldID = 0;

    try {//from  w ww  .j  a va2s .  c om
        fieldID = Integer.parseInt(args[0]);
    } catch (NumberFormatException e) {
        log.error("Illegal field id -" + e.getMessage());
        return;
    }

    TableProto.Column col1 = TableProto.Column.newBuilder().setUint32(fieldID).build();
    TableProto.Column col2 = TableProto.Column.newBuilder().setString(args[1]).build();
    List<TableProto.Column> cols = new ArrayList<TableProto.Column>();
    cols.add(col1);
    cols.add(col2);

    TableProto.Row row = TableProto.Row.newBuilder().addAllColumns(cols).build();
    try {

        boolean success = false;
        if (update) {
            success = stub.replaceRow(tableName, row);
        } else {
            success = stub.insertRow(tableName, row);
        }
        if (success) {
            log.info("Row successfully inserted");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:example.TableExample.java

@java.lang.Override
public String query(ChaincodeStub stub, String function, String[] args) {
    log.info("query");
    int fieldID = 0;

    try {/*from w w w.j av  a2 s .  co  m*/
        fieldID = Integer.parseInt(args[0]);
    } catch (NumberFormatException e) {
        log.error("Illegal field id -" + e.getMessage());
        return "ERROR querying ";
    }
    TableProto.Column queryCol = TableProto.Column.newBuilder().setUint32(fieldID).build();
    List<TableProto.Column> key = new ArrayList<>();
    key.add(queryCol);
    switch (function) {
    case "get": {
        try {
            TableProto.Row tableRow = stub.getRow(tableName, key);
            if (tableRow.getSerializedSize() > 0) {
                return tableRow.getColumns(1).getString();
            } else {
                return "No record found !";
            }
        } catch (Exception invalidProtocolBufferException) {
            invalidProtocolBufferException.printStackTrace();
        }
    }
    default:
        log.error("No matching case for function:" + function);
        return "";
    }

}