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:Main.java

public static long parseLong(String num) {
    Long lon = -1l;/*from w  w  w.  j  a  va2  s . c om*/
    try {
        lon = Long.parseLong(num);
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }
    return lon;
}

From source file:Main.java

public static String formatDuration(int duration) {
    String result = "00:00";
    try {//from   www  . j a  v a2  s .  c  om
        long du = duration / 1000;
        result = String.format("%02d:%02d", du / 60, du % 60);
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:Main.java

/**
 * @param duration : 302000/* w w  w  . j  a  v a  2s .com*/
 * @return 5:02
 */
public static String formatDuration(String duration) {
    String result = duration;
    try {
        long du = Integer.parseInt(result) / 1000;
        result = String.format("%02d:%02d", du / 60, du % 60);
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:Main.java

/**
 * Get the shared preference about knn from localization method.
 *
 * @param context The calling context.//from  w  w  w . jav a 2 s  .  c o  m
 * @return Integer from preferences. If not a number, return value will be 3.
 */
public static int getPrefKnn(Context context) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    int value = 3;

    try {
        value = Integer.valueOf(sharedPreferences.getString("localization_knn", "3"));
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }

    return value;
}

From source file:Main.java

public static String[] getCalendarShowTime(String paramString) {
    try {/*ww w.j  ava 2  s.  c  o m*/
        long l = Long.valueOf(paramString);
        Calendar localCalendar = Calendar.getInstance();
        localCalendar.setTimeInMillis(1000L * l);
        return getCalendarShowTime(localCalendar.getTimeInMillis());
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static Color readColorAttr(Element element, String attributeName, Color defaultValue) {
    String s = element.getAttribute(attributeName);

    if (s == null || s.charAt(0) != '#') {
        return defaultValue;
    }//from w ww  .  ja v  a2  s  . c o  m

    try {
        return new Color(Integer.parseInt(s.substring(1), 16), false);
    } catch (NumberFormatException e) {
        e.printStackTrace();
        return defaultValue;
    }
}

From source file:Main.java

public static String shortRelativeTime(Date d) {
    try {//w  w  w. jav  a 2  s  . c o  m
        Period p = new Period(new DateTime(d), DateTime.now());
        if (p.getYears() > 0) {
            return WEEKS_IN_A_YEAR * p.getYears() + WEEKS_SHORT_SUFFIX;
        } else if (p.getMonths() > 0) {
            return WEEKS_IN_A_MONTH * p.getMonths() + WEEKS_SHORT_SUFFIX;
        } else if (p.toStandardWeeks().getWeeks() > 0) {
            return p.toStandardWeeks().getWeeks() + WEEKS_SHORT_SUFFIX;
        } else if (p.toStandardDays().getDays() > 0) {
            return p.toStandardDays().getDays() + DAYS_SHORT_SUFFIX;
        } else if (p.toStandardHours().getHours() > 0) {
            return p.toStandardHours().getHours() + HOURS_SHORT_SUFFIX;
        } else if (p.toStandardMinutes().getMinutes() > 0) {
            return p.toStandardMinutes().getMinutes() + MINUTES_SHORT_SUFFIX;
        } else {
            return p.toStandardSeconds().getSeconds() + SECONDS_SHORT_SUFFIX;
        }
    } catch (NumberFormatException e) {
        e.printStackTrace();
        return "";
    }
}

From source file:Main.java

public static int parseInt(String num) {
    Integer intNum = 0;/*from w w  w . j ava2  s . c o  m*/
    try {
        intNum = Integer.parseInt(num);
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }
    return intNum;
}

From source file:Main.java

public static int getStationFromUI(TextView textView) {
    int station = 0;
    float frequency = 0;
    String frequencyStr = textView.getText().toString();
    try {/*from w ww.  java  2 s.c  om*/
        frequency = Float.parseFloat(frequencyStr);
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }
    station = (int) (frequency * CONVERT_RATE);
    return station;
}

From source file:Main.java

public static boolean phoneNumberRule(String phone) {
    boolean result = false;
    long min = 13000000000L;
    long max = 18999999999L;
    long data = 0;
    try {/*from   w  w  w  . j a v a 2s .  co  m*/
        data = Long.parseLong(phone);
    } catch (NumberFormatException e) {
        result = false;
        e.printStackTrace();
    }
    if (phone.length() != 11)
        result = false;
    else if (data < min || data > max)
        result = false;
    else
        result = true;
    return result;
}