Example usage for java.lang NumberFormatException printStackTrace

List of usage examples for java.lang NumberFormatException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.diversityarrays.kdxplore.curate.TraitsAndInstancesPanel2.java

private OutlierSelection createOutlierSelection(SimpleStatistics<?> stats, TraitInstance ti) {
    Bag<?> lowOutliers = stats.getLowOutliers();
    Bag<?> highOutliers = stats.getHighOutliers();

    Double maxMin = Double.MAX_VALUE;
    Double maxMax = 0.0;//from  w  w  w . ja  v a  2 s. com
    Comparable<?> max = stats.getMaxValue();
    int count = 0;
    for (Object o : highOutliers) {

        String val = String.valueOf(o);
        try {
            Double inter = Double.parseDouble(val);
            if (inter < maxMin) {
                maxMin = inter;
            }

            if (count == 0) {
                maxMax = Double.parseDouble(String.valueOf(max));
            }
            count++;
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
    }

    Double minMin = 0.0;
    Double minMax = Double.MIN_VALUE;
    Comparable<?> min = stats.getMinValue();
    count = 0;
    for (Object o : lowOutliers) {

        String val = String.valueOf(o);
        try {
            Double inter = Double.parseDouble(val);
            if (inter > minMax) {
                minMax = inter;
            }

            if (count == 0) {
                minMin = Double.parseDouble(String.valueOf(min));
            }
            count++;
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
    }

    OutlierSelection selection = new OutlierSelection(minMin, minMax, maxMin, maxMax, ti);
    return selection;
}

From source file:com.example.camera360.ui.ImageDetailActivity.java

private void setFavoriteUsers(String result, int index) {
    if (result.equals("")) {
        showDetailView(1, 0);/*from w ww .j a  v  a 2s  . com*/
        return;
    }

    try {
        JSONObject object = new JSONObject(result);

        if (Integer.parseInt(object.getString("status")) == HttpStatus.SC_OK) {
            JSONObject data = object.getJSONObject("data");
            HashMap<String, String> map = arrayList.get(index);
            String count = data.getString("favoriteCount");
            int favoriteCount = Integer.parseInt(count);
            JSONArray favoriteUsers = data.getJSONArray("favoriteUsers");
            map.put("count", count);

            if (favoriteCount == 0) {
                showDetailView(1, 0);
            } else {
                String item = favoriteUsers.join(",").replaceAll("\"", "") + "" + favoriteCount
                        + "";

                map.put("favoriteInfo", item);

                if (index == currentIndex) {
                    mImageDetailLoad.setVisibility(View.GONE);
                    mImageDetailText.setText(item);
                }
            }
        } else {
            showDetailView(1, 0);
        }
    } catch (NumberFormatException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:geo.controller.GeoCodeServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from w  w w . j  a v  a  2s. c om
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    response.setContentType("application/json");
    PrintWriter out = response.getWriter();
    try {
        String token = getTokenFromAPI();
        ArrayList<Transaction> transactionList = getAllTransactions();
        ArrayList<MRTStation> mrtList = getAllMRTStation();
        String[] coordinate = null;
        String result = null;
        /*
        for(Transaction t:transactionList){
        result = geoCodeTransactions(token,t);
        if (result.equals("")){
            result = geoCodeTransactions2(t);
        }
                
        if(result.equals("")){
            out.println(t.address);
            out.println(t.postalCode);
            out.println(result);
            continue;
        }
                
        coordinate = result.split(",");
        try{
            t.lng = Double.parseDouble(coordinate[0]);
            t.lat = Double.parseDouble(coordinate[1]);
        } catch (NumberFormatException e){
            out.println(t.address);
            out.println(t.postalCode);
            out.println(result);
        }
        }
                
        TransactionDAO.addPostalGeocodes(transactionList);
        */

        for (MRTStation m : mrtList) {
            result = geoCodeMRT(token, m);

            if (result.equals("")) {
                out.println(m.code);
                out.println(m.stationName);
                out.println(result);
                continue;
            }

            coordinate = result.split(",");
            try {
                m.lng = Double.parseDouble(coordinate[0]);
                m.lat = Double.parseDouble(coordinate[1]);
            } catch (NumberFormatException e) {
                out.println(m.code);
                out.println(m.stationName);
                out.println(result);
            }
        }

        MRTStationDAO.addStationGeocodes(mrtList);

        out.println("Success");

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:ark.model.SupervisedModelCreg.java

@Override
protected AssignmentList toParseInternalHelper(AssignmentList internalAssignments) {
    TreeMap<Double, List<String>> sortedWeights = new TreeMap<Double, List<String>>();
    File modelFile = new File(this.modelPath.getValue());

    if (!modelFile.exists())
        return internalAssignments;

    try {//from  w  w  w  . j  a va2 s  .co  m
        BufferedReader br = new BufferedReader(new FileReader(modelFile));
        String line = null;

        while ((line = br.readLine()) != null) {
            String[] lineParts = line.split("\t");
            Double value = null;
            if (lineParts.length < 3)
                continue;
            try {
                value = Math.abs(Double.parseDouble(lineParts[2]));
            } catch (NumberFormatException e) {
                continue;
            }

            if (!sortedWeights.containsKey(value))
                sortedWeights.put(value, new ArrayList<String>());
            sortedWeights.get(value).add(line);
        }

        br.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    NavigableMap<Double, List<String>> descendingWeights = sortedWeights.descendingMap();
    int i = 0;
    for (List<String> lines : descendingWeights.values()) {
        for (String line : lines) {
            internalAssignments
                    .add(Assignment.assignmentTyped(null, Context.ARRAY_STR, "w-" + i, Obj.stringValue(line)));

            i++;
        }
    }

    return internalAssignments;
}

From source file:com.androzic.waypoint.WaypointProperties.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_save:
        Androzic application = Androzic.getApplication();
        try {/*from   w  ww.  j  av  a2  s.  com*/
            if (name.getText().length() == 0)
                return false;

            if (waypoint == null) {
                waypoint = new Waypoint();
            }
            if (waypoint.date == null) {
                waypoint.date = Calendar.getInstance().getTime();
            }

            waypoint.name = name.getText().toString();

            waypoint.description = description.getText().toString();
            Angle[] coords = getLatLon();
            waypoint.latitude = coords[0].degrees;
            waypoint.longitude = coords[1].degrees;

            try {
                String p = proximity.getText().toString();
                if ("".equals(p))
                    waypoint.proximity = 0;
                else
                    waypoint.proximity = Integer.parseInt(p);
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }

            try {
                String a = altitude.getText().toString();
                if ("".equals(a))
                    waypoint.altitude = Integer.MIN_VALUE;
                else
                    waypoint.altitude = Integer.parseInt(a);
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }

            if (iconValue == null) {
                waypoint.marker = "";
                waypoint.drawImage = false;
            } else {
                waypoint.marker = iconValue;
                waypoint.drawImage = true;
            }
            int markerColorValue = markercolor.getColor();
            if (markerColorValue != defMarkerColor)
                waypoint.backcolor = markerColorValue;
            int textColorValue = textcolor.getColor();
            if (textColorValue != defTextColor)
                waypoint.textcolor = textColorValue;

            if (route != null) {
                application.dispatchRoutePropertiesChanged(route);
            } else {
                if (waypoint.set == null) {
                    application.addWaypoint(waypoint);
                }

                int set = waypointSet.getSelectedItemPosition();
                waypoint.set = application.getWaypointSets().get(set);

                application.saveWaypoints();
            }

            // Hide keyboard
            final InputMethodManager imm = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
            // "Close" fragment
            getFragmentManager().popBackStack();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(getActivity(), "Invalid input", Toast.LENGTH_LONG).show();
        }
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:gov.nih.nci.system.web.struts.action.CreateAction.java

private void setParameterValue(Class klass, Object instance, String name, String value)
        throws NumberFormatException, Exception {
    if (value != null && value.trim().length() == 0)
        value = null;/*from   www  .  jav  a2s . c o m*/

    try {
        String paramName = name.substring(0, 1).toUpperCase() + name.substring(1);
        Method[] allMethods = klass.getMethods();
        for (Method m : allMethods) {
            String mname = m.getName();
            if (mname.equals("get" + paramName)) {
                Class type = m.getReturnType();
                Class[] argTypes = new Class[] { type };

                Method method = null;
                while (klass != Object.class) {
                    try {
                        Method setMethod = klass.getDeclaredMethod("set" + paramName, argTypes);
                        setMethod.setAccessible(true);
                        Object converted = convertValue(type, value);
                        if (converted != null)
                            setMethod.invoke(instance, converted);
                        break;
                    } catch (NumberFormatException e) {
                        throw e;
                    } catch (NoSuchMethodException ex) {
                        klass = klass.getSuperclass();
                    } catch (Exception e) {
                        throw e;
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}

From source file:de.baumann.hhsmoodle.data_random.Random_Fragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {

    case R.id.action_help:
        helper_main.switchToActivity(getActivity(), Random_Help.class, false);
        return true;

    case R.id.action_dice:
        android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(
                getActivity());/*from   www .  j  a v  a2 s.co m*/
        View dialogView = View.inflate(getActivity(), R.layout.dialog_dice, null);

        final TextView textChoose2 = (TextView) dialogView.findViewById(R.id.textChoose);
        final EditText editNumber2 = (EditText) dialogView.findViewById(R.id.editNumber);
        editNumber2.setHint(R.string.number_dice_hint);

        builder.setView(dialogView);
        builder.setTitle(R.string.number_dice);
        builder.setPositiveButton(R.string.toast_yes, null);
        builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int whichButton) {
                dialog.cancel();
            }
        });

        final android.support.v7.app.AlertDialog dialog2 = builder.create();
        // Display the custom alert dialog on interface
        dialog2.setOnShowListener(new DialogInterface.OnShowListener() {

            @Override
            public void onShow(DialogInterface dialog) {

                Button b = dialog2.getButton(android.support.v7.app.AlertDialog.BUTTON_POSITIVE);
                b.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        try {
                            number = Integer.parseInt(editNumber2.getText().toString());
                            Random rand = new Random();
                            int n = rand.nextInt(number);
                            textChoose2.setText(String.valueOf(n + 1));
                        } catch (NumberFormatException nfe) {
                            Snackbar.make(textChoose2, R.string.number_dice_error, Snackbar.LENGTH_LONG).show();
                            nfe.printStackTrace();
                        }
                    }
                });
            }
        });

        dialog2.show();
        helper_main.showKeyboard(getActivity(), editNumber2);
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.megaeyes.web.controller.UserController.java

/**
 * @Title: updateUser/*from  w ww. j ava 2  s . co m*/
 * @Description: 
 * @param @param request
 * @param @param response
 * @param @throws UnsupportedEncodingException 
 * @return void 
 * @throws
 */
@ControllerDescription(description = "?", isLog = true, isCheckSession = true)
@RequestMapping("/updateUser.json")
public void updateUser(HttpServletRequest request, HttpServletResponse response)
        throws UnsupportedEncodingException {
    request.setCharacterEncoding("UTF-8");
    BaseResponse resp = new BaseResponse();
    String id = (String) request.getAttribute("userId");
    String logonName = (String) request.getAttribute("logonName");
    String password = (String) request.getAttribute("password");
    String accessServerId = (String) request.getAttribute("accessServerId");
    String note = (String) request.getAttribute("note");
    String name = (String) request.getAttribute("name");
    String naming = (String) request.getAttribute("naming");
    String sex = (String) request.getAttribute("sex");
    Long age = null;
    String age1 = (String) request.getAttribute("age");
    if (StringUtils.isNotBlank(age1)) {
        try {
            age = Long.parseLong(age1);
        } catch (NumberFormatException be) {
            resp.setCode(ErrorCode.PARAMETER_VALUE_INVALIDED);
            resp.setMessage("age");
        }
    }
    String mobile = (String) request.getAttribute("mobile");
    String phone = (String) request.getAttribute("phone");
    String email = (String) request.getAttribute("email");
    Long maxSession = null;
    String maxSession1 = (String) request.getAttribute("maxSession");
    if (StringUtils.isNotBlank(maxSession1)) {
        try {
            maxSession = Long.parseLong(maxSession1);
        } catch (NumberFormatException be) {
            resp.setCode(ErrorCode.PARAMETER_VALUE_INVALIDED);
            resp.setMessage("maxSession");
        }
    }
    String userAccount = null;
    Short priority = null;
    String priority1 = (String) request.getAttribute("priority");
    if (StringUtils.isNotBlank(priority1)) {
        try {
            priority = Short.parseShort(priority1);
        } catch (NumberFormatException be) {
            resp.setCode(ErrorCode.PARAMETER_VALUE_INVALIDED);
            resp.setMessage("priority");
        }
    }
    String sipCode = (String) request.getAttribute("sipCode");
    String dispatchServerId = (String) request.getAttribute("dispatchServerId");
    if ("null".equals(dispatchServerId)) {
        dispatchServerId = "";
    }
    // ?
    Short isInnerUser = null;
    String isInnerUserString = request.getParameter("isInnerUser");
    if (StringUtils.isNotBlank(isInnerUserString)) {
        try {
            isInnerUser = Short.parseShort(isInnerUserString);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            resp.setCode(ErrorCode.PARAMETER_VALUE_INVALIDED);
            resp.setMessage("isInnerUser");
        }
    }
    if (resp.getCode().equals(ErrorCode.SUCCESS)) {
        try {
            userManager.updateUser(id, logonName, password, accessServerId, note, name, naming, sex, age,
                    mobile, phone, email, maxSession, userAccount, priority, sipCode, dispatchServerId,
                    isInnerUser);
            resp.setCode(ErrorCode.SUCCESS);
        } catch (BusinessException be) {
            resp.setCode(be.getCode());
            resp.setMessage(be.getMessage());
        }
    }
    writePageNoZip(response, resp);

}

From source file:com.megaeyes.web.controller.UserController.java

/**
 * @Title: createUser/*from   w w w  .  j a  v a 2s . c o  m*/
 * @Description: 
 * @param request
 * @param response
 *            
 * @return void 
 * @throws
 */
@ControllerDescription(description = "", isLog = true, isCheckSession = true)
@RequestMapping("/createUser.json")
public void createUser(HttpServletRequest request, HttpServletResponse response)
        throws UnsupportedEncodingException {
    BaseResponse resp = new BaseResponse();
    request.setCharacterEncoding("UTF-8");
    // License
    resp.setCode(checkUserLicence());

    String logonName = (String) request.getAttribute("logonName");
    String password = (String) request.getAttribute("password");
    String organId = (String) request.getAttribute("organId");
    String accessServerId = (String) request.getAttribute("accessServerId");
    String note = (String) request.getAttribute("note");
    String name = (String) request.getAttribute("name");
    String sex = (String) request.getAttribute("sex");
    Long age = (long) 20;
    String age1 = (String) request.getAttribute("age");
    if (StringUtils.isNotBlank(age1)) {
        try {
            age = Long.parseLong(age1);
        } catch (NumberFormatException be) {
            resp.setCode(ErrorCode.PARAMETER_VALUE_INVALIDED);
            resp.setMessage("age");
        }
    }
    String mobile = (String) request.getAttribute("mobile");
    String phone = (String) request.getAttribute("phone");
    String email = (String) request.getAttribute("email");
    Short isSuspend = 0;
    Long maxSession = (long) 4;
    String maxSession1 = (String) request.getAttribute("maxSession");
    if (StringUtils.isNotBlank(maxSession1)) {
        try {
            maxSession = Long.parseLong(maxSession1);
        } catch (NumberFormatException be) {
            resp.setCode(ErrorCode.PARAMETER_VALUE_INVALIDED);
            resp.setMessage("maxSession");
        }
    }
    String userAccount = "0";
    Short priority = 1;
    String priority1 = (String) request.getAttribute("priority");
    if (StringUtils.isNotBlank(priority1)) {
        try {
            priority = Short.parseShort(priority1);
        } catch (NumberFormatException be) {
            resp.setCode(ErrorCode.PARAMETER_VALUE_INVALIDED);
            resp.setMessage("priority");
        }
    }
    String sipCode = (String) request.getAttribute("sipCode");
    String dispatchServerId = (String) request.getAttribute("dispatchServerId");
    if ("null".equals(dispatchServerId)) {
        dispatchServerId = "";
    }
    // ?
    Short isInnerUser = 1;
    String isInnerUserString = request.getParameter("isInnerUser");
    if (StringUtils.isNotBlank(isInnerUserString)) {
        try {
            isInnerUser = Short.parseShort(isInnerUserString);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            resp.setCode(ErrorCode.PARAMETER_VALUE_INVALIDED);
            resp.setMessage("isInnerUser");
        }
    }
    if (resp.getCode().equals(ErrorCode.SUCCESS)) {
        try {
            String id = userManager.createUser(logonName, password, organId, accessServerId, note, name, sex,
                    age, mobile, phone, email, isSuspend, maxSession, userAccount, priority, sipCode,
                    dispatchServerId, isInnerUser);
            // System.out.println("---------------"+id);
            resp.setCode(ErrorCode.SUCCESS);
            resp.setMessage(id);
        } catch (BusinessException be) {
            resp.setCode(be.getCode());
            resp.setMessage(be.getMessage());
        }
    }
    writePageNoZip(response, resp);
}

From source file:edu.cornell.mannlib.vitro.webapp.visualization.mapofscience.MapOfScienceVisualizationRequestHandler.java

private ScienceMappingResult getScienceMappingResult(Map<String, Integer> journalToPublicationCount) {
    ScienceMappingResult result = null;/*from   www  . ja  va 2s  .  co  m*/
    try {
        result = (new ScienceMapping()).generateScienceMappingResult(journalToPublicationCount);
    } catch (NumberFormatException e) {
        System.err.println("NumberFormatException coming from Map Of Science Vis");
        e.printStackTrace();
    } catch (IOException e) {
        System.err.println("IOException coming from Map Of Science Vis");
        e.printStackTrace();
    }
    return result;
}