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:no.barentswatch.implementation.FiskInfoUtility.java

/**
 * Checks that the given string contains coordinates in a valid format in
 * regards to the given projection./*from w  w  w  .  j a  v  a  2  s. c om*/
 * 
 * @param coordinates
 *            the coordinates to be checked.
 * @return true if coordinates are in a valid format.
 */

private boolean checkProjectionEPSG3857(String coordinates) {
    try {
        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 EPSG3857MinX = -20026376.39;
        double EPSG3857MaxX = 20026376.39;
        double EPSG3857MinY = -20048966.10;
        double EPSG3857MaxY = 20048966.10;

        if (latitude < EPSG3857MinX || latitude > EPSG3857MaxX || longitude < EPSG3857MinY
                || longitude > EPSG3857MaxY) {
            return false;
        }

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

From source file:org.simbrain.plot.histogram.HistogramPanel.java

/**
 * Construct a new histogram panel.//from   w  ww  . java  2 s . c  o  m
 *
 * @param model
 *            reference to underlying data
 */
public HistogramPanel(final HistogramModel model) {
    this.model = model;
    this.setLayout(new BorderLayout());

    setPreferredSize(dimPref);
    createHistogram();

    JPanel buttonPanel = new JPanel();
    JButton clearButton = new JButton("Clear");
    clearButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            model.resetData();
        }
    });
    buttonPanel.add(clearButton);
    buttonPanel.add(binButton);
    buttonPanel.add(numBinLabel);
    numBins.setText("" + model.getBins());
    buttonPanel.add(numBins);

    binButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            HistogramModel model = HistogramPanel.this.getModel();
            try {
                model.setBins(Integer.parseInt(numBins.getText()));
                model.redraw();
            } catch (NumberFormatException nfe) {
                nfe.printStackTrace();
                JOptionPane.showMessageDialog(getParent(), "Non-Integer number of bins.", "Error",
                        JOptionPane.ERROR);
            }
        }

    });

    this.add("South", buttonPanel);
    this.add("Center", mainPanel);

}

From source file:gov.nih.nci.cabig.caaers.web.study.DiseaseTab.java

private void handleStudyDiseaseAction(Errors errors, StudyCommand command, String action, String selected,
        HttpServletRequest request) {//from w ww  .java  2 s  .  co m

    if ("addMeddraStudyDisease".equals(action) && command.getDiseaseLlt().length() > 0
            && command.getStudy().getDiseaseTerminology().getDiseaseCodeTerm() == DiseaseCodeTerm.MEDDRA) {
        String diseaseCode = command.getDiseaseLlt();
        MeddraStudyDisease meddraStudyDisease = new MeddraStudyDisease();
        // meddraStudyDisease.setMeddraCode(diseaseCode);
        meddraStudyDisease.setTerm(
                lowLevelTermDao.getById(Integer.parseInt(diseaseCode)) == null ? lowLevelTermDao.getById(1)
                        : lowLevelTermDao.getById(Integer.parseInt(diseaseCode)));
        command.getStudy().addMeddraStudyDisease(meddraStudyDisease);
    }

    if ("removeMeddraStudyDisease".equals(action)) {
        command.deleteMeddraStudyDiseaseAtIndex(Integer.parseInt(selected));
    }

    if (action.equals("addOtherCondition")) {

        Condition condition = null;
        int conditionId = 0;

        try {
            conditionId = Integer.parseInt(command.getCondition());
        } catch (NumberFormatException e) {
            log.warn("Incorrect ID for the Condition Object.");
            e.printStackTrace();
        }
        StudyCondition studyCondition = new StudyCondition();

        if (conditionId > 0) {
            condition = conditionDao.getById(conditionId);
            studyCondition.setTerm(condition);
        } else {

            Condition newCondition = new Condition();
            if (StringUtils.isNotBlank(request.getParameter("condition-input")))
                newCondition.setConditionName(
                        StringEscapeUtils.escapeHtml(request.getParameter("condition-input")));

            if (checkDuplicateConditionByText(conditionMap, newCondition.getConditionName())) {
                errors.reject("DUPLICATE_STUDY_CONDITION", new Object[] { newCondition.getConditionName() },
                        "");
            } else {
                conditionDao.save(newCondition);
                studyCondition.setTerm(newCondition);
            }

        }
        if (!errors.hasErrors())
            command.getStudy().addStudyCondition(studyCondition);
    }

    if (action.equals("removeOtherCondition")) {
        try {
            command.deleteStudyConditionAtIndex(Integer.parseInt(selected));
        } catch (IndexOutOfBoundsException e) {
            log.warn("No <StudyCondition> at the position: " + selected);
        }
    }

    if ("addStudyDisease".equals(action)
            && command.getStudy().getDiseaseTerminology().getDiseaseCodeTerm() == DiseaseCodeTerm.CTEP) {
        String[] diseases = command.getDiseaseTermIds();
        log.debug("Study Diseases Size : " + command.getStudy().getCtepStudyDiseases().size());
        for (String diseaseId : diseases) {
            log.debug("Disease Id : " + diseaseId);
            CtepStudyDisease ctepStudyDisease = new CtepStudyDisease();
            ctepStudyDisease.setTerm(diseaseTermDao.getById(Integer.parseInt(diseaseId)));
            command.getStudy().addCtepStudyDisease(ctepStudyDisease);

        }
    } else if ("removeStudyDisease".equals(action)) {
        command.deleteCtepStudyDiseaseAtIndex(Integer.parseInt(selected));
    }
}

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

private boolean checkProjectionEPSG900913(String coordinates) {
    try {/*w w w  .j a v  a2 s.  co  m*/
        int commaSeperatorIndex = coordinates.indexOf(",");
        double latitude = Double.parseDouble(coordinates.substring(0, commaSeperatorIndex - 1));
        double longitude = Double
                .parseDouble(coordinates.substring(commaSeperatorIndex + 1, coordinates.length() - 1));

        /*
         * These are based on the spherical metricator bounds of OpenLayers
         * and as we are currently using OpenLayer these are bounds to use.
         */
        double EPSG900913MinX = -20037508.34;
        double EPSG900913MaxX = 20037508.34;
        double EPSG900913MinY = -20037508.34;
        double EPSG900913MaxY = 20037508.34;

        if (latitude < EPSG900913MinX || latitude > EPSG900913MaxX || longitude < EPSG900913MinY
                || longitude > EPSG900913MaxY) {
            return false;
        }

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

From source file:com.company.project.service.dao.RedisDao.java

/**
 * 4.9. Redis Transactions - http://docs.spring.io/spring-data/redis/docs/current/reference/html/
 * Add value to set. Utilize Session Callback
 * @param key/* w  w  w .j ava2 s.  c o m*/
 * @param value
 * @return 
 */
public long addUsingOpsForSetUsingSesssionCallback(final String key, final Object value) {
    //execute a transaction
    List<Object> txResults = redisTemplate.execute(new SessionCallback<List<Object>>() {
        @Override
        public List<Object> execute(RedisOperations operations) throws DataAccessException {
            operations.multi();
            operations.opsForSet().add(key, value);

            // This will contain the results of all ops in the transaction
            return operations.exec();
        }
    });

    if (txResults != null && !txResults.isEmpty()) {
        System.out.println("Number of items added to set: " + txResults.get(0));
        try {
            int itemsAdded = Integer.parseInt("" + txResults.get(0));
            return itemsAdded;
        } catch (NumberFormatException nfe) {
            nfe.printStackTrace();
        }
    }

    return 0;
}

From source file:nl.hnogames.domoticz.UI.LocationDialog.java

public void show() {

    if (UsefulBits.isEmpty(title))
        mdb.title(R.string.title_add_location);
    else//from   w ww .j a v a 2  s  .co m
        mdb.title(title);

    MaterialDialog md = mdb.build();
    View view = md.getCustomView();

    initViews(view);

    if (radius <= 0)
        radius = radiusDefaultValue;
    setRadiusText(String.valueOf(radius));

    if (currentLocation != null) {
        // Adding a new location
        setAddressName(mContext.getString(R.string.currentLocation));

        Address currentAddress = mGeoUtil.getAddressFromLocation(currentLocation);
        if (currentAddress != null)
            setAddressData(currentAddress);
        else {
            resolvedAddress.setText(R.string.unknown);
            resolvedCountry.setText(R.string.unknown);
        }
    } else if (locationToEdit != null) {
        // Editing a location
        setAddressName(locationToEdit.getName());

        Address addressToEdit = mGeoUtil.getAddressFromLocationInfo(locationToEdit);
        if (addressToEdit != null)
            setAddressData(addressToEdit);
        else {
            resolvedAddress.setText(R.string.unknown);
            resolvedCountry.setText(R.string.unknown);
        }

    }

    getLocation.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (inManualMode()) {
                foundLocation = mGeoUtil
                        .getAddressFromString(String.valueOf(editAddress.getInputWidgetText().toString()));
                if (foundLocation == null)
                    Toast.makeText(mContext, R.string.could_not_find_location, Toast.LENGTH_SHORT).show();
                else
                    setAddressData(foundLocation);
            } else {
                try {
                    double latitude = Double.valueOf(editLatitude.getInputWidgetText().toString());
                    double longitude = Double.valueOf(editLongitude.getInputWidgetText().toString());
                    LatLng mLatLng = new LatLng(latitude, longitude);
                    foundLocation = mGeoUtil.getAddressFromLatLng(mLatLng);
                    if (foundLocation == null)
                        Toast.makeText(mContext, R.string.could_not_find_location, Toast.LENGTH_SHORT).show();
                    else
                        setAddressData(foundLocation);

                } catch (NumberFormatException e) {
                    e.printStackTrace();
                    Toast.makeText(mContext, R.string.no_valid_latLong, Toast.LENGTH_SHORT).show();
                }
            }
        }
    });

    editModeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (inManualMode())
                setEditModeToManual(false);
            else
                setEditModeToManual(true);
        }
    });
    md.show();
}

From source file:com.pactera.edg.am.metamanager.extractor.adapter.extract.db.impl.DbFromFileExtractServiceImpl.java

/**
 * ??//from  w w w . j av a 2s  .  co  m
 * 
 * @param line
 *            ??
 */
private void genColumn(String line) {
    try {
        String[] split = line.split(SEPARATOR);
        if (split.length < 17) {
            log.error(":" + Arrays.toString(split));
            return;
        }

        // if(split[2].matches("==\\$0$")){
        // return;
        // }
        Column column = new Column();
        column.setName(split[3]);
        column.setDataType(Integer.valueOf(split[4]).intValue());
        column.setTypeName(split[5]);

        column.setColumnSize(Integer.valueOf(split[6]).intValue());
        column.setBufferLength(Integer.valueOf(split[7]).intValue());
        column.setNumPrecRadix(Integer.valueOf(split[9]).intValue());
        column.setRemarks(split[11]);
        column.addAttr(ModelElement.REMARKS, split[11]);

        column.setColumnDef(split[12]);
        column.setSqlDataType(Integer.valueOf(split[13]).intValue());
        column.setSqlDatetimeSub(Integer.valueOf(split[14]).intValue());
        column.setCharOctetLength(Integer.valueOf(split[15]).intValue());

        column.setOrdinalPosition(Integer.valueOf(split[16]).intValue());
        if ("YES".equals(split[17])) {
            column.setNullable(true);
        } else {
            column.setNullable(false);
        }

        // 
        columnSetCache.get(split[1] + split[2]).addColumn(column);

    } catch (NumberFormatException e) {
        System.err.println("line:" + line);
        e.printStackTrace();
    }

}

From source file:com.libreteam.taxi.Customer_Fragment_Activity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = getApplicationContext();//from   www .  java  2 s .  com
    isMenu = false;
    isInMenu = false;
    isInCalling = false;
    setContentView(this.getLayoutInflater().inflate(R.layout.main_fragment_activity, null));
    Taxi_System.setContent((FrameLayout) findViewById(R.id.dummy), getApplicationContext(), 1, (float) 0.07);
    Taxi_System.setContent((FrameLayout) findViewById(R.id.banner), getApplicationContext(), 1, (float) 0.05);
    button = (Button) findViewById(R.id.menu);
    button.getLayoutParams().width = (int) (Taxi_System.getHeight(context) * 0.07);
    button.getLayoutParams().height = (int) (Taxi_System.getHeight(context) * 0.07);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!isMenu)
                getSupportFragmentManager().beginTransaction().setCustomAnimations(R.anim.abc_fade_in, 0)
                        .replace(R.id.menuframe, new Customer_Information(), "menu").disallowAddToBackStack()
                        .commitAllowingStateLoss();
            else
                getSupportFragmentManager().beginTransaction().setCustomAnimations(0, R.anim.abc_fade_out)
                        .remove(getSupportFragmentManager().findFragmentByTag("menu")).disallowAddToBackStack()
                        .commitAllowingStateLoss();
            isMenu = !isMenu;
        }
    });

    setActivity();
    Socket.respond = new SocketRespond() {
        @Override
        public void respondData(String string) {
            Taxi_System.testLog("CUSTOMER-MAIN" + string);
            if (Taxi_System.getSystem(context, "type").equalsIgnoreCase("user")) {
                try {
                    didReceiveCode(Integer.valueOf(new JSONObject(string).getString("code").toString()),
                            string);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    };

}

From source file:org.kalypso.ogc.sensor.view.observationDialog.ObservationViewer.java

private int[] getWeightsFromSettings(final int[] defaultWeights, final String section) {
    if (m_settings == null)
        return defaultWeights;

    final String[] array = m_settings.getArray(section);
    if (array == null || array.length != defaultWeights.length)
        return defaultWeights;

    final int[] weights = new int[defaultWeights.length];
    try {// www . j  a va 2  s .c o m
        for (int i = 0; i < weights.length; i++)
            weights[i] = Integer.parseInt(array[i]);
        return weights;
    } catch (final NumberFormatException e) {
        e.printStackTrace();
        return defaultWeights;
    }
}

From source file:dk.netarkivet.harvester.tools.TwitterDecidingScope.java

/**
 * This routine makes any necessary Twitter API calls and queues the content discovered.
 *
 * @param controller The controller for this crawl.
 *///w ww. j a v a  2s.c om
@Override
public void initialize(CrawlController controller) {
    super.initialize(controller);
    twitter = (new TwitterFactory()).getInstance();
    keywords = null;
    try {
        keywords = (StringList) super.getAttribute(ATTR_KEYWORDS);
        pages = ((Integer) super.getAttribute(ATTR_PAGES)).intValue();
        geoLocations = (StringList) super.getAttribute(ATTR_GEOLOCATIONS);
        language = (String) super.getAttribute(ATTR_LANG);
        if (language == null) {
            language = "all";
        }
        resultsPerPage = (Integer) super.getAttribute(ATTR_RESULTS_PER_PAGE);
        queueLinks = (Boolean) super.getAttribute(ATTR_QUEUE_LINKS);
        queueUserStatus = (Boolean) super.getAttribute(ATTR_QUEUE_USER_STATUS);
        queueUserStatusLinks = (Boolean) super.getAttribute(ATTR_QUEUE_USER_STATUS_LINKS);
        queueKeywordLinks = (Boolean) super.getAttribute(ATTR_QUEUE_KEYWORD_LINKS);
    } catch (AttributeNotFoundException e1) {
        e1.printStackTrace();
        throw new RuntimeException(e1);
    } catch (MBeanException e1) {
        e1.printStackTrace();
        throw new RuntimeException(e1);
    } catch (ReflectionException e1) {
        e1.printStackTrace();
        throw new RuntimeException(e1);
    }
    for (Object keyword : keywords) {
        log.info("Twitter Scope keyword: {}", keyword);
    }
    // If keywords or geoLocations is missing, add a list with a single empty string so that the main loop is
    // executed at least once.
    if (keywords == null || keywords.isEmpty()) {
        keywords = new StringList("keywords", "empty keyword list", new String[] { "" });
    }
    if (geoLocations == null || geoLocations.isEmpty()) {
        geoLocations = new StringList("geolocations", "empty geolocation list", new String[] { "" });
    }
    log.info("Twitter Scope will queue {} page(s) of results.", pages);
    // Nested loop over keywords, geo_locations and pages.
    for (Object keyword : keywords) {
        String keywordString = (String) keyword;
        for (Object geoLocation : geoLocations) {
            String urlQuery = (String) keyword;
            Query query = new Query();
            query.setRpp(resultsPerPage);
            if (language != null && !language.equals("")) {
                query.setLang(language);
                urlQuery += " lang:" + language;
                keywordString += " lang:" + language;
            }
            urlQuery = "http://twitter.com/search/" + URLEncoder.encode(urlQuery);
            if (queueKeywordLinks) {
                addSeedIfLegal(urlQuery);
            }
            for (int page = 1; page <= pages; page++) {
                query.setPage(page);
                if (!keyword.equals("")) {
                    query.setQuery(keywordString);
                }
                if (!geoLocation.equals("")) {
                    String[] locationArray = ((String) geoLocation).split(",");
                    try {
                        GeoLocation location = new GeoLocation(Double.parseDouble(locationArray[0]),
                                Double.parseDouble(locationArray[1]));
                        query.setGeoCode(location, Double.parseDouble(locationArray[2]), locationArray[3]);
                    } catch (NumberFormatException e) {
                        e.printStackTrace();
                    }
                }
                try {
                    final QueryResult result = twitter.search(query);
                    List<Tweet> tweets = result.getTweets();
                    for (Tweet tweet : tweets) {
                        long id = tweet.getId();
                        String fromUser = tweet.getFromUser();
                        String tweetUrl = "http://www.twitter.com/" + fromUser + "/status/" + id;
                        addSeedIfLegal(tweetUrl);
                        tweetCount++;
                        if (queueLinks) {
                            extractEmbeddedLinks(tweet);
                        }
                        if (queueUserStatus) {
                            String statusUrl = "http://twitter.com/" + tweet.getFromUser() + "/";
                            addSeedIfLegal(statusUrl);
                            linkCount++;
                            if (queueUserStatusLinks) {
                                queueUserStatusLinks(tweet.getFromUser());
                            }
                        }
                    }
                } catch (TwitterException e1) {
                    log.error(e1.getMessage());
                }
            }
        }

    }
    System.out.println(
            TwitterDecidingScope.class + " added " + tweetCount + " tweets and " + linkCount + " other links.");
}