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.objectweb.proactive.extensions.timitspmd.util.charts.Line2dChart.java

/**
 * Creates a dataset/* w w w .j  a  v a 2s. c  om*/
 *
 * @return The dataset.
 */
@SuppressWarnings("unchecked")
private CategoryDataset createDataset() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    int i;
    int k;
    Comparable currentCategory;
    Element currentElement;
    Element iteratedElement;
    Iterator it;
    String currentTagName;
    String attributeNameValue;
    String stringValue;
    double value;

    // Iterate through the categories
    for (i = 0; (i < this.categories.length) && (i < this.series.length); i++) {
        currentCategory = this.categories[i];
        currentElement = this.series[i];
        // Iterate through the selected Element
        it = currentElement.getDescendants();
        while (it.hasNext()) {
            Object o = it.next();
            if (o instanceof Element) {
                iteratedElement = (Element) o;
                currentTagName = iteratedElement.getName();
                if (currentTagName.equals(this.wantedTag)) {
                    for (k = 0; k < this.names.length; k++) {
                        attributeNameValue = iteratedElement.getAttributeValue("name");
                        if ((attributeNameValue != null) && attributeNameValue.equals(this.names[k])) {
                            stringValue = iteratedElement.getAttributeValue(this.selectedAttributeName);
                            if (stringValue != null) {
                                try {
                                    value = Double.parseDouble(stringValue);
                                    dataset.setValue(value,
                                            attributeNameValue + " (" + this.selectedAttributeName + ")",
                                            currentCategory);
                                } catch (NumberFormatException ex) {
                                    ex.printStackTrace();
                                }
                            } else {
                                System.out.println("No attribute " + this.selectedAttributeName + " for tag "
                                        + this.wantedTag + " with name " + this.names[k]);
                            }
                        }
                    }
                }
            }
        }
    }

    return dataset;
}

From source file:org.apache.click.control.ImageSubmit.java

/**
 * Bind the request submission, setting the field {@link Submit#clicked},
 * {@link #x} and {@link #y} if defined in the request.
 *//*  www.  j  a va2 s . c om*/
@Override
public void bindRequestValue() {

    Context context = getContext();

    // Note IE does not submit name
    String xValue = context.getRequestParameter(getName() + ".x");

    if (xValue != null) {
        this.clicked = true;

        try {
            this.x = Integer.parseInt(xValue);
        } catch (NumberFormatException nfe) {
            nfe.printStackTrace();
        }

        String yValue = context.getRequestParameter(getName() + ".y");
        try {
            this.y = Integer.parseInt(yValue);
        } catch (NumberFormatException nfe) {
            nfe.printStackTrace();
        }
    }
}

From source file:im.ene.lab.attiq.ui.activities.TagItemsActivity.java

/**
 * Get item-count header from API then update item count
 *
 * @param headers from API's response//from ww w . j av  a  2 s .c o  m
 */
@Override
public void onResponseHeaders(Headers headers) {
    if (headers != null) {
        String itemCount = headers.get(Header.Response.TOTAL_COUNT);
        try { // catch NumberFormatException, in case their API returns something weird
            ((State) mState).itemCount = Integer.valueOf(itemCount);
            EventBus.getDefault().post(new StateEvent<>(getClass().getSimpleName(), true, null, mState));
        } catch (NumberFormatException er) {
            er.printStackTrace();
        }
    }
}

From source file:org.generationcp.breeding.manager.crossingmanager.SelectGermplasmListTreeComponent.java

public void displayGermplasmListDetails(int germplasmListId) throws InternationalizableException {
    try {/*from ww  w  . j a  v  a  2 s  .co m*/
        displayGermplasmListInfo(germplasmListId);
    } catch (NumberFormatException e) {
        LOG.error(e.toString() + "\n" + e.getStackTrace());
        e.printStackTrace();
        MessageNotifier.showWarning(messageSource.getMessage(Message.ERROR_INVALID_FORMAT),
                messageSource.getMessage(Message.ERROR_IN_NUMBER_FORMAT), Position.MIDDLE_CENTER);
    } catch (MiddlewareQueryException e) {
        LOG.error(e.toString() + "\n" + e.getStackTrace());
        throw new InternationalizableException(e, Message.ERROR_DATABASE,
                Message.ERROR_IN_CREATING_GERMPLASMLIST_DETAILS_WINDOW);
    }

}

From source file:com.trial.phonegap.plugin.calendar.CalendarAccessorMock.java

/**
 * Return a true boolean value if the given parameter is an eventCalendar and it is in the current calendar
 * @param eventCalendar//  w  w w  .j  a v  a  2  s  .com
 * @return a boolean
 */
private boolean exists(JSONObject eventCalendar) {

    try {

        if ((eventCalendar.isNull("id"))
                || (Integer.parseInt(eventCalendar.getString("id")) >= calendar1.size())
                || (calendar1.get(Integer.parseInt(eventCalendar.getString("id"))) == null)) {
            return false;
        }
    } catch (NumberFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
        return false;
    }
    return true;

}

From source file:com.trial.phonegap.plugin.calendar.CalendarAccessorMock.java

/**
 * //from www. ja  v  a  2 s  .com
 */
@Override
public boolean save(JSONObject newCalendarEvent) {
    try {
        if (exists(newCalendarEvent)) {
            calendar1.set(Integer.parseInt(newCalendarEvent.getString("id")), newCalendarEvent);
        } else {
            calendar1.add(newCalendarEvent);
            newCalendarEvent.put("id", String.valueOf(calendar1.indexOf(newCalendarEvent)));
        }
    } catch (NumberFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:games.strategy.engine.random.PropertiesDiceRoller.java

/**
 * /* www.ja  v a2s .  c o m*/
 * @throws IOException
 *             if there was an error parsing the string
 */
public int[] getDice(final String string, final int count) throws IOException, InvocationTargetException {
    final String errorStartString = m_props.getProperty("error.start");
    final String errorEndString = m_props.getProperty("error.end");
    // if the error strings are defined
    if (errorStartString != null && errorStartString.length() > 0 && errorEndString != null
            && errorEndString.length() > 0) {
        final int startIndex = string.indexOf(errorStartString);
        if (startIndex >= 0) {
            final int endIndex = string.indexOf(errorEndString, (startIndex + errorStartString.length()));
            if (endIndex > 0) {
                final String error = string.substring(startIndex + errorStartString.length(), endIndex);
                throw new InvocationTargetException(null, error);
            }
        }
    }
    String rollStartString;
    String rollEndString;
    if (count == 1) {
        rollStartString = m_props.getProperty("roll.single.start");
        rollEndString = m_props.getProperty("roll.single.end");
    } else {
        rollStartString = m_props.getProperty("roll.multiple.start");
        rollEndString = m_props.getProperty("roll.multiple.end");
    }
    int startIndex = string.indexOf(rollStartString);
    if (startIndex == -1) {
        throw new IOException("Cound not find start index, text returned is:" + string);
    }
    startIndex += rollStartString.length();
    final int endIndex = string.indexOf(rollEndString, startIndex);
    if (endIndex == -1) {
        throw new IOException("Cound not find end index");
    }
    final StringTokenizer tokenizer = new StringTokenizer(string.substring(startIndex, endIndex), " ,", false);
    final int[] rVal = new int[count];
    for (int i = 0; i < count; i++) {
        try {
            // -1 since we are 0 based
            rVal[i] = Integer.parseInt(tokenizer.nextToken()) - 1;
        } catch (final NumberFormatException ex) {
            ex.printStackTrace();
            throw new IOException(ex.getMessage());
        }
    }
    return rVal;
}

From source file:com.tinfoil.sms.settings.QuickPrefsActivity.java

/**
 * Things done when the preference menu is created  
 * Left as default// w  ww . jav  a2s.c om
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setupActionBar();
    /*
     * Add preferences from the options.xml file.
     */
    addPreferencesFromResource(R.xml.options);

    setKitKatPref();

    PreferenceScreen sourceCode = (PreferenceScreen) findPreference(SOURCE_CODE_SETTING_KEY);
    sourceCode.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(QuickPrefsActivity.this.getString(R.string.tinfoil_sms_github)));
            QuickPrefsActivity.this.startActivity(i);

            return true;
        }

    });

    EditTextPreference vibrateLength = (EditTextPreference) findPreference(VIBRATE_LENGTH_SETTING_KEY);
    vibrateLength.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            boolean ret = false;

            try {
                if (SMSUtility.isASmallNumber(newValue.toString())
                        && Integer.valueOf(newValue.toString()) > 0) {
                    ret = true;
                }
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
            return ret;
        }

    });

    //TODO implement the OnPreferenceChangeListener for the other preferences that use numbers only
    EditTextPreference messageLimit = (EditTextPreference) findPreference(MESSAGE_LIMIT_SETTING_KEY);
    messageLimit.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            boolean ret = false;

            try {
                if (SMSUtility.isASmallNumber(newValue.toString())
                        && Integer.valueOf(newValue.toString()) > 0) {
                    ret = true;
                }
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
            return ret;
        }
    });

    findPreference("enable_walkthrough").setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            // If walkthrough enabled, reset all the steps so they are displayed again
            if (Boolean.valueOf(newValue.toString())) {
                Walkthrough.enableWalkthrough(QuickPrefsActivity.this);
            } else {
                Walkthrough.disableWalkthrough(QuickPrefsActivity.this);
            }
            return true;
        }
    });

    /* Set an onclick listener for contact developers */
    findPreference("contact").setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            /**
             * Create the Intent
             */
            final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

            /**
             * Fill it with Data
             */
            emailIntent.setType("plain/text");
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                    QuickPrefsActivity.this.getResources().getStringArray(R.array.dev_emails));
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                    getResources().getString(R.string.email_subject));
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "");

            /**
             * Send it off to the Activity-Chooser
             */
            QuickPrefsActivity.this.startActivity(Intent.createChooser(emailIntent,
                    QuickPrefsActivity.this.getResources().getString(R.string.email_chooser)));
            return true;
        }
    });
}

From source file:application.controllers.admin.EditEmotion.java

private String uploadNewImage(HttpServletRequest request, HttpServletResponse response) {
    String linkImage = emotionSelected.linkImage;
    if (!ServletFileUpload.isMultipartContent(request)) {
        return "";
    }/*from w w w.  j  ava  2 s  .  co m*/
    // configures upload settings
    DiskFileItemFactory factory = new DiskFileItemFactory();
    // maximum size that will be stored in memory
    factory.setSizeThreshold(UploadConstant.THRESHOLD_SIZE);
    // Location to save data that is larger than maxMemSize.
    factory.setRepository(new File(System.getProperty("java.io.tmpdir")));
    // Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload(factory);
    // maximum file size to be uploaded.
    upload.setFileSizeMax(UploadConstant.MAX_FILE_SIZE);
    upload.setSizeMax(UploadConstant.MAX_REQUEST_SIZE);

    // constructs the directory path to store upload file
    //groupEmotionId chinh la folder chua
    // creates the directory if it does not exist
    String[] arrLink = emotionSelected.linkImage.split("/");
    if (arrLink.length < 3) {
        return "";
    }
    try {
        List formItems = upload.parseRequest(request);
        Iterator iter = formItems.iterator();
        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();
            // processes only fields that are not form fields
            if (item.isFormField()) {
                //form field
                if (item.getFieldName().equals("groupEmotion")) {
                    try {
                        if (emotionSelected.groupEmotionId != Integer.parseInt(item.getString())) {
                            //thay doi group id --> chuyen file sang folder tuong ung va thay doi imagelink
                            //chuyen file sang folder tuong ung theo group da chon

                            String sourcePath = Registry.get("imageHost") + emotionSelected.linkImage;
                            //item.getString --> groupEmotion chon
                            String desPath = Registry.get("imageHost") + "/emotions-image/" + item.getString()
                                    + "/" + arrLink[3];

                            File sourceDir = new File(sourcePath);
                            File desDir = new File(desPath);
                            if (sourceDir.exists()) {
                                FileUtils.copyFile(sourceDir, desDir);
                                sourceDir.delete();

                            }

                            emotionSelected.groupEmotionId = Integer.parseInt(item.getString());
                            linkImage = "/emotions-image/" + emotionSelected.groupEmotionId + "/" + arrLink[3];

                        }
                    } catch (NumberFormatException ex) {
                        ex.printStackTrace();
                    }
                }
                if (item.getFieldName().equals("description")) {
                    emotionSelected.description = item.getString();
                }
                if (item.getFieldName().equals("imageURL")) {
                    emotionSelected.linkImage = item.getString();

                }
            } else {

                String fileName = new File(item.getName()).getName();
                //file name bang empty khi ko upload new image
                if ("".equals(fileName)) {
                    continue;
                }
                String filePath = Registry.get("imageHost") + emotionSelected.linkImage;
                File newImage = new File(filePath);
                File oldImage = new File(filePath);
                // xoa image cu bi edit
                if (oldImage.exists()) {
                    oldImage.delete();
                }
                // save image moi vao  folder cua group id va cung ten moi image cu
                item.write(newImage);

                //save lai file cua image moi
                linkImage = "/emotions-image/" + emotionSelected.groupEmotionId + "/" + arrLink[3];
            }
        }

    } catch (Exception ex) {
        Logger.getLogger(EditEmotion.class.getName()).log(Level.SEVERE, null, ex);
    }
    return linkImage;

}

From source file:jp.g_aster.social.action.StampAction.java

/**
 * ?QR????/*from w  w  w  . ja  v a2s . com*/
 * @return
 */
public ActionResult showQRCode() {

    if (!this.isLogin()) {
        return new Redirect("/");
    }
    try {
        this.stampDto = stampService.getStamp(authKey);
        if (stampDto.getFileId() == MemberImageFile.FILEID_NOIMAGE) {
            stampDto.setMemberFileUrl("/img/noimage.png");
        }

    } catch (NumberFormatException e) {
        e.printStackTrace();
        return new Forward("/common/error.jsp");
    } catch (DataNotFoundException e) {
        e.printStackTrace();
        return new Forward("/common/error.jsp");
    }
    return new Forward("/stamp/viewQRCode.jsp");
}