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:org.kalypso.model.wspm.tuhh.core.wprof.BCEShapeWPRofContentProvider.java

@Override
public BigDecimal getStation() {
    final double station = getProperty("STATION", Double.class, Double.NaN); //$NON-NLS-1$
    if (Double.isNaN(station) || station < -99990.00)
        return null;

    try {/*from  w  ww. j a v  a 2 s .  c om*/
        final double faktorStation = 1;
        return new BigDecimal(station / faktorStation).setScale(4, BigDecimal.ROUND_HALF_UP);
    } catch (final NumberFormatException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:org.jahia.loganalyzer.internal.JahiaLogAnalyzerImpl.java

@Override
public void retrieveBuildInformation() {
    try {/*ww  w . j a va  2  s .  c om*/
        URL urlToMavenPom = JahiaLogAnalyzerImpl.class.getClassLoader()
                .getResource("/META-INF/jahia-loganalyzer-marker.txt");
        if (urlToMavenPom != null) {
            URLConnection urlConnection = urlToMavenPom.openConnection();
            if (urlConnection instanceof JarURLConnection) {
                JarURLConnection conn = (JarURLConnection) urlConnection;
                JarFile jarFile = conn.getJarFile();
                Manifest manifest = jarFile.getManifest();
                Attributes attributes = manifest.getMainAttributes();
                buildNumber = attributes.getValue("Implementation-Build");
                version = attributes.getValue("Implementation-Version");
                String buildTimestampValue = attributes.getValue("Implementation-Timestamp");
                if (buildTimestampValue != null) {
                    try {
                        long buildTimestampTime = Long.parseLong(buildTimestampValue);
                        buildTimestamp = new Date(buildTimestampTime);
                    } catch (NumberFormatException nfe) {
                        nfe.printStackTrace();
                    }
                }
            }
        }
    } catch (IOException ioe) {
        log.error("Error while trying to retrieve build information", ioe);
    } catch (NumberFormatException nfe) {
        log.error("Error while trying to retrieve build information", nfe);
    }
}

From source file:za.co.neilson.alarm.alert.AlarmAlertActivity.java

public boolean isAnswerCorrect() {
    boolean correct = false;
    try {//w  ww  .j a  v  a  2  s. com
        correct = mathProblem.getAnswer() == Float.parseFloat(answerBuilder.toString());
    } catch (NumberFormatException e) {
        return false;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return correct;
}

From source file:org.opendatakit.data.ColorRule.java

public boolean checkMatch(ElementDataType type, Row row) {
    try {/*from   ww w. java2s .  c om*/
        // Get the value we're testing against.
        String testValue = row.getDataByKey(mElementKey);

        // nulls are never matched (mValue is never null)
        if (testValue == null) {
            return false;
        }

        int compVal;
        if ((type == ElementDataType.number || type == ElementDataType.integer)) {
            double doubleValue = Double.parseDouble(testValue);
            double doubleRule = Double.parseDouble(mValue);
            compVal = (Double.valueOf(doubleValue)).compareTo(Double.valueOf(doubleRule));
        } else {
            compVal = testValue.compareTo(mValue);
        }
        switch (mOperator) {
        case LESS_THAN:
            return (compVal < 0);
        case LESS_THAN_OR_EQUAL:
            return (compVal <= 0);
        case EQUAL:
            return (compVal == 0);
        case GREATER_THAN_OR_EQUAL:
            return (compVal >= 0);
        case GREATER_THAN:
            return (compVal > 0);
        default:
            throw new IllegalArgumentException("unrecognized op passed to checkMatch: " + mOperator);
        }
    } catch (NumberFormatException e) {
        // this should never happen
        e.printStackTrace();
        throw new IllegalArgumentException("error parsing value as number, removing the offending rule");
    }
}

From source file:edu.ksu.cs.a4vm.bse.MorphologyActivity.java

@Override
public void onResume() {
    super.onResume();
    //loading stored data
    morphologyLabels = (HashSet<String>) SharedPrefUtil.getValue(getApplicationContext(),
            Constant.PREFS_FILE_MORPH_INFO, Constant.KEY_MORPHOLOGY);
    if (morphologyLabels != null && morphologyLabels.size() <= fields.size()) {
        Iterator<EditText> it = fields.iterator();
        for (String label : morphologyLabels) {
            String[] text = label.split("=");
            if (label.contains("Limit=")) {

                if (text != null && text.length == 2)
                    limit.setText(text[1]);
            } else if (label.contains("Morphology Field 2")) {
                if (text != null && text.length == 2)
                    field2.setText(text[1]);
            } else if (label.contains("Morphology Field 3")) {
                if (text != null && text.length == 2)
                    field3.setText(text[1]);
            } else if (label.contains("Morphology Field 4")) {
                if (text != null && text.length == 2)
                    field4.setText(text[1]);
            } else if (label.contains("Morphology Field 5")) {
                if (text != null && text.length == 2)
                    field5.setText(text[1]);
            } else if (label.contains("Morphology Field 6")) {
                if (text != null && text.length == 2)
                    field6.setText(text[1]);
            } else if (label.contains("Morphology Field 7")) {
                if (text != null && text.length == 2)
                    field7.setText(text[1]);
            } else if (label.contains("Morphology Field 8")) {
                if (text != null && text.length == 2)
                    field8.setText(text[1]);
            }/*from   ww w .  jav a 2s . c om*/

        }
    }

    limit.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            try {
                int n = Integer.parseInt(limit.getText().toString().trim());
                if (n > 0) {
                    isLimitValid = true;
                    limit.setBackground(
                            ContextCompat.getDrawable(getApplicationContext(), R.drawable.focus_color));
                } else {
                    isLimitValid = false;
                    limit.setBackground(
                            ContextCompat.getDrawable(getApplicationContext(), R.drawable.highlight));
                    Toast.makeText(getApplicationContext(), "Limit must be an integer greater than 0",
                            Toast.LENGTH_SHORT).show();
                }
            } catch (NumberFormatException ne) {
                ne.printStackTrace();
                isLimitValid = false;
                limit.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.highlight));
                Toast.makeText(getApplicationContext(), "Limit must be an integer greater than 0",
                        Toast.LENGTH_SHORT).show();
            }
        }
    });

    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            HashSet<String> keys = new HashSet<String>();

            String key = field2.getText().toString().trim();
            if (key.length() > 0) {
                key = "Morphology Field 2=" + key;
                keys.add(key);
            }

            key = field3.getText().toString().trim();
            if (key.length() > 0) {
                key = "Morphology Field 3=" + key;
                keys.add(key);
            }

            key = field4.getText().toString().trim();
            if (key.length() > 0) {
                key = "Morphology Field 4=" + key;
                keys.add(key);
            }

            key = field5.getText().toString().trim();
            if (key.length() > 0) {
                key = "Morphology Field 5=" + key;
                keys.add(key);
            }

            key = field6.getText().toString().trim();
            if (key.length() > 0) {
                key = "Morphology Field 6=" + key;
                keys.add(key);
            }

            key = field7.getText().toString().trim();
            if (key.length() > 0) {
                key = "Morphology Field 7=" + key;
                keys.add(key);
            }

            key = field8.getText().toString().trim();
            if (key.length() > 0) {
                key = "Morphology Field 8=" + key;
                keys.add(key);
            }

            key = limit.getText().toString().trim();
            try {
                int n = Integer.parseInt(limit.getText().toString().trim());
                if (n > 0) {
                    isLimitValid = true;
                    key = "Limit=" + key;
                    keys.add(key);
                    limit.setBackground(
                            ContextCompat.getDrawable(getApplicationContext(), R.drawable.focus_color));
                } else {
                    isLimitValid = false;
                    limit.setBackground(
                            ContextCompat.getDrawable(getApplicationContext(), R.drawable.highlight));
                    Toast.makeText(getApplicationContext(), "Limit must be an integer greater than 0",
                            Toast.LENGTH_SHORT).show();
                }
            } catch (NumberFormatException ne) {
                ne.printStackTrace();
                isLimitValid = false;
                limit.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.highlight));
                Toast.makeText(getApplicationContext(), "Limit must be an integer greater than 0",
                        Toast.LENGTH_SHORT).show();
            }

            if (isLimitValid) {
                SharedPrefUtil.saveMorphologyKeys(getApplicationContext(), keys);
                Toast.makeText(getApplicationContext(), "Saved!", Toast.LENGTH_LONG).show();
                Intent goPrev = new Intent(getApplicationContext(), SettingsActivity.class);
                startActivity(goPrev);
            }

        }
    });

}

From source file:org.opendatakit.common.android.data.ColorRule.java

public boolean checkMatch(ElementDataType type, Row row) {
    try {/*from  w  ww .  ja  va 2s. c om*/
        // Get the value we're testing against.
        String testValue = row.getRawDataOrMetadataByElementKey(mElementKey);

        // nulls are never matched (mValue is never null)
        if (testValue == null) {
            return false;
        }

        int compVal;
        if ((type == ElementDataType.number || type == ElementDataType.integer)) {
            double doubleValue = Double.parseDouble(testValue);
            double doubleRule = Double.parseDouble(mValue);
            compVal = (Double.valueOf(doubleValue)).compareTo(Double.valueOf(doubleRule));
        } else {
            compVal = testValue.compareTo(mValue);
        }
        switch (mOperator) {
        case LESS_THAN:
            return (compVal < 0);
        case LESS_THAN_OR_EQUAL:
            return (compVal <= 0);
        case EQUAL:
            return (compVal == 0);
        case GREATER_THAN_OR_EQUAL:
            return (compVal >= 0);
        case GREATER_THAN:
            return (compVal > 0);
        default:
            throw new IllegalArgumentException("unrecognized op passed to checkMatch: " + mOperator);
        }
    } catch (NumberFormatException e) {
        // this should never happen
        e.printStackTrace();
        throw new IllegalArgumentException("error parsing value as number, removing the offending rule");
    }
}

From source file:org.kalypso.wspwin.core.WspCfg.java

private IStatus readWspCfg(final File profDir, final Collection<ZustandBean> zustandBeans) {
    final File wspCfgFile = new File(profDir, WspWinFiles.WSP_CFG);

    try (LineNumberReader reader = new LineNumberReader(new FileReader(wspCfgFile))) {
        final String firstLine = reader.readLine();
        if (firstLine == null || firstLine.length() == 0)
            return new Status(IStatus.ERROR, KalypsoWspWinCorePlugin.PLUGIN_ID,
                    Messages.getString("org.kalypso.wspwin.core.WspCfg.1")); //$NON-NLS-1$

        // ignore the values, we read the count from the linecount
        // just parse the type
        final char type = firstLine.charAt(firstLine.length() - 1);
        setType(type);//w w  w. j a  va 2  s.  c  o m

        while (reader.ready()) {
            final String line = reader.readLine();
            if (line == null)
                break;

            final String trimmedLine = line.trim();
            if (trimmedLine.length() == 0 || trimmedLine.length() < 85)
                continue;

            try {
                final String waterName = trimmedLine.substring(0, 15).trim();
                final String name = trimmedLine.substring(15, 30).trim();
                // normally it should always be german, but it depends on the wspwin installation
                final DateFormat dateInstance = SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT,
                        Locale.GERMAN);
                final String dateString = trimmedLine.substring(30, 41).trim();
                final Date date = dateInstance.parse(dateString);
                final BigDecimal start = new BigDecimal(trimmedLine.substring(41, 56).trim());
                final BigDecimal end = new BigDecimal(trimmedLine.substring(56, 71).trim());
                final String fileName = trimmedLine.substring(71).trim();

                final ZustandBean zustandBean = new ZustandBean(name, waterName, fileName, start, end, date);
                zustandBeans.add(zustandBean);
            } catch (final NumberFormatException e) {
                e.printStackTrace();
                throw new ParseException(
                        Messages.getString("org.kalypso.wspwin.core.WspCfg.3", reader.getLineNumber()), //$NON-NLS-1$
                        reader.getLineNumber());
            }
        }

        return Status.OK_STATUS;
    } catch (final ParseException | IOException e) {
        return new Status(IStatus.ERROR, KalypsoWspWinCorePlugin.PLUGIN_ID, e.getLocalizedMessage(), e);
    }
}

From source file:edu.lternet.pasta.portal.search.MapResultSetUtility.java

private String composeLocationField(String coordinates, Set<String> coordinatesSet, boolean useOffset) {
    String field = null;//from   ww w .  ja v a2  s.  c o m
    double lat = 0;
    double lon = 0;

    if (coordinates != null && coordinates.contains(" ")) {
        String[] tokens = coordinates.split(" ");
        if (tokens.length == 4) {
            String wStr = tokens[0];
            String sStr = tokens[1];
            String eStr = tokens[2];
            String nStr = tokens[3];
            try {
                if (wStr.equals(eStr)) {
                    lon = Double.parseDouble(wStr);
                } else {
                    double wLon = Double.parseDouble(wStr);
                    double eLon = Double.parseDouble(eStr);
                    lon = avg(wLon, eLon);
                }

                if (sStr.equals(nStr)) {
                    lat = Double.parseDouble(sStr);
                } else {
                    double sLat = Double.parseDouble(sStr);
                    double nLat = Double.parseDouble(nStr);
                    lat = avg(sLat, nLat);
                }
            } catch (NumberFormatException e) {
                e.printStackTrace();
                return null;
            }

            /*
             * If we need to use an offset, tweak the values a little bit
             * to make them unique
             */
            if (useOffset) {
                lat = lat + (Math.random() - 0.5) / 1500;
                lon = lon + (Math.random() - 0.5) / 1500;
            }

            field = String.format("'location': {'latitude':%f, 'longitude': %f}", lat, lon);

            /*
             * Ensure that we have a unique pair of coordinates. If we don't, call
             * this method recursively using an offset.
             */
            if (coordinatesSet.contains(field)) {
                useOffset = true;
                field = composeLocationField(coordinates, coordinatesSet, useOffset);
            }
        }
    }

    return field;
}

From source file:no.barentswatch.implementation.FiskInfoUtility.java

private boolean checkProjectionEPSG4326(String coordinates) {
    try {/*www .  j av  a 2  s  .c  om*/
        int commaSeperatorIndex = coordinates.indexOf(",");
        double latitude = Double.parseDouble(coordinates.substring(0, commaSeperatorIndex - 1));
        double longitude = Double
                .parseDouble(coordinates.substring(commaSeperatorIndex + 1, coordinates.length() - 1));
        double EPSG4326MinX = -180.0;
        double EPSG4326MaxX = 180.0;
        double EPSG4326MinY = -90.0;
        double EPSG4326MaxY = 90.0;

        if (latitude < EPSG4326MinX || latitude > EPSG4326MaxX || longitude < EPSG4326MinY
                || longitude > EPSG4326MaxY) {
            return false;
        }

        return true;
    } catch (NumberFormatException e) {
        e.printStackTrace();
        return false;
    } catch (StringIndexOutOfBoundsException e) {
        e.printStackTrace();
        return false;
    }
}

From source file:no.barentswatch.implementation.FiskInfoUtility.java

private boolean checkProjectionEPSG23030(String coordinates) {
    try {/*from   ww  w .  ja  v a2  s  .  c om*/
        int commaSeperatorIndex = coordinates.indexOf(",");
        double latitude = Double.parseDouble(coordinates.substring(0, commaSeperatorIndex - 1));
        double longitude = Double
                .parseDouble(coordinates.substring(commaSeperatorIndex + 1, coordinates.length() - 1));
        double EPSG23030MinX = 229395.8528;
        double EPSG23030MaxX = 770604.1472;
        double EPSG23030MinY = 3982627.8377;
        double EPSG23030MaxY = 7095075.2268;

        if (latitude < EPSG23030MinX || latitude > EPSG23030MaxX || longitude < EPSG23030MinY
                || longitude > EPSG23030MaxY) {
            return false;
        }

        return true;
    } catch (NumberFormatException e) {
        e.printStackTrace();
        return false;
    } catch (StringIndexOutOfBoundsException e) {
        e.printStackTrace();
        return false;
    }
}