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:naftoreiclag.flowchartarch.ParseFiler.java

public static void writeGenes(Genes genes) {
    StringBuilder builder = new StringBuilder();

    appendElementData(builder, 0, genes);

    try {/*  w  w  w .j  a  va  2s. co m*/
        FileUtils.writeStringToFile(new File("file.txt"), builder.toString());
        System.out.println("   Successuful print");
    } catch (NumberFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

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

private static int parseVZK(final String token) {
    try {/*from   ww  w  . j ava2 s . c om*/
        return Integer.parseInt(token.trim());
    } catch (final NumberFormatException e) {
        e.printStackTrace();
        return 0;
    }
}

From source file:org.glom.Utils.java

public static void transformUnknownToActualType(final TypedDataItem dataItem, final GlomFieldType actualType) {
    if (dataItem.getType() == actualType)
        return;//from ww w .ja v  a  2  s. c  om

    String unknownText = dataItem.getUnknown();

    //Avoid repeated checks for null:
    if (unknownText == null) {
        unknownText = "";
    }

    switch (actualType) {
    case TYPE_NUMERIC:
        // TODO: Is this really locale-independent?
        double number = 0;
        if (!StringUtils.isEmpty(unknownText)) {
            try {
                number = Double.parseDouble(unknownText);
            } catch (final NumberFormatException e) {
                e.printStackTrace();
            }
        }

        dataItem.setNumber(number);
        break;
    case TYPE_TEXT:
        dataItem.setText(unknownText);
        break;
    case TYPE_DATE:
        final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = formatter.parse(unknownText);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        dataItem.setDate(date);
        break;
    case TYPE_TIME:
        /*TODO :
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date date;
        try {
        date = formatter.parse(unknownText);
        } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        }
                
        setDate(date); 
        */
        break;
    case TYPE_BOOLEAN:
        final boolean bool = unknownText.equals("true");
        dataItem.setBoolean(bool); //TODO
        break;
    case TYPE_IMAGE:
        dataItem.setImageDataUrl(unknownText);
        //setImageData(null);//TODO: Though this is only used for primary keys anyway.
        break;
    case TYPE_INVALID:
        break;
    default:
        break; //TODO: Warn because this is unusual?
    }
}

From source file:com.yahoo.semsearch.fastlinking.EntityContextFastEntityLinker.java

/**
 * Reads a type mapping file (from short integer to string). Useful for display
 *
 * @param types type remapping//from   ww  w.  j  a  v a  2s.c o  m
 * @return hashmap with the remmaped types
 * @throws IOException
 */
public static HashMap<Short, String> readTypeMapping(String types) throws IOException {
    HashMap<Short, String> typeMapping = new HashMap<>();
    final BufferedReader lines = new BufferedReader(new FileReader(types));
    String line;
    while ((line = lines.readLine()) != null) {
        String[] parts = line.split("\t");
        try {
            typeMapping.put(new Short(parts[1]), parts[0]);
        } catch (NumberFormatException e) {
            System.out.println("Wrong line: " + line);
            e.printStackTrace();
        }
    }
    lines.close();
    return typeMapping;
}

From source file:com.vendsy.bartsy.venue.GCMIntentService.java

/**
 * To generate a notification to inform the user that server has sent a message.
 * //from  www  .ja va 2 s . c o  m
 * @param count
 * @param count 
 */
private static void generateNotification(Context context, String message, String count) {
    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);

    Intent notificationIntent = new Intent(context, MainActivity.class);
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    try {
        int countValue = Integer.parseInt(count);
        notification.number = countValue;
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }

    // // Play default notification sound
    notification.defaults = Notification.DEFAULT_SOUND;
    notificationManager.notify(0, notification);
}

From source file:eu.udig.style.jgrass.core.PredefinedColorRules.java

public static List<RuleValues> getRulesValuesList(String[][] colorRules, double[] dataRange)
        throws IOException {
    List<RuleValues> list = new ArrayList<RuleValues>();
    if (colorRules[0].length == 3) {
        /*// ww w  . ja  v  a  2s  .  com
         * the colorrules are without values, so we ramp through them
         * over the range. 
         */
        if (dataRange == null) {
            dataRange = new double[] { -100.0, 5000 };
        }

        // calculate the color increment
        float rinc = (float) (dataRange[1] - dataRange[0]) / (float) (colorRules.length - 1);

        for (int i = 0; i < colorRules.length - 1; i++) {
            try {
                double from = dataRange[0] + (i * rinc);
                Color fromColor = new Color(Integer.parseInt(colorRules[i][0]),
                        Integer.parseInt(colorRules[i][1]), Integer.parseInt(colorRules[i][2]));
                double to = dataRange[0] + ((i + 1) * rinc);
                Color toColor = new Color(Integer.parseInt(colorRules[i + 1][0]),
                        Integer.parseInt(colorRules[i + 1][1]), Integer.parseInt(colorRules[i + 1][2]));
                RuleValues rV = new RuleValues();
                rV.fromValue = from;
                rV.toValue = to;
                rV.fromColor = fromColor;
                rV.toColor = toColor;
                list.add(rV);
            } catch (NumberFormatException e) {
                e.printStackTrace();
                continue;
            }
        }

        // rule.append((dataRange[1] - rinc) + ":");
        // rule.append(colorRules[colorRules.length - 2][0] + ":"
        // + colorRules[colorRules.length - 2][1] + ":"
        // + colorRules[colorRules.length - 2][2] + " ");
        // rule.append((dataRange[1]) + ":");
        // rule.append(colorRules[colorRules.length - 1][0] + ":"
        // + colorRules[colorRules.length - 1][1] + ":"
        // + colorRules[colorRules.length - 1][2] + "\n");

    } else {
        /*
         * in this case we have also the values for the range defined
         * and the color rule has to be "v1 r1 g1 b1 v2 r2 g2 b2". 
         */
        if (colorRules[0].length != 8) {
            throw new IOException("The colortable can have records of 3 or 8 columns. Check your colortables.");
        }

        for (int i = 0; i < colorRules.length; i++) {
            try {
                double from = Double.parseDouble(colorRules[i][0]);
                Color fromColor = new Color(Integer.parseInt(colorRules[i][1]),
                        Integer.parseInt(colorRules[i][2]), Integer.parseInt(colorRules[i][3]));
                double to = Double.parseDouble(colorRules[i][4]);
                Color toColor = new Color(Integer.parseInt(colorRules[i][5]),
                        Integer.parseInt(colorRules[i][6]), Integer.parseInt(colorRules[i][7]));
                RuleValues rV = new RuleValues();
                rV.fromValue = from;
                rV.toValue = to;
                rV.fromColor = fromColor;
                rV.toColor = toColor;
                list.add(rV);
            } catch (NumberFormatException e) {
                e.printStackTrace();
                continue;
            }
        }

    }
    return list;

}

From source file:eu.udig.style.advanced.raster.PredefinedColorRules.java

public static List<RuleValues> getRulesValuesList(String[][] colorRules, double[] dataRange)
        throws IOException {
    List<RuleValues> list = new ArrayList<RuleValues>();
    if (colorRules[0].length == 3) {
        /*/*from  w  w  w.  j  a  v  a  2 s  .com*/
         * the colorrules are without values, so we ramp through them
         * over the range. 
         */
        if (dataRange == null) {
            dataRange = new double[] { -100.0, 5000 };
        }

        // calculate the color increment
        float rinc = (float) (dataRange[1] - dataRange[0]) / (float) (colorRules.length - 1);

        for (int i = 0; i < colorRules.length - 1; i++) {
            try {
                double from = dataRange[0] + (i * rinc);
                Color fromColor = new Color(Integer.parseInt(colorRules[i][0]),
                        Integer.parseInt(colorRules[i][1]), Integer.parseInt(colorRules[i][2]));
                double to = dataRange[0] + ((i + 1) * rinc);
                Color toColor = new Color(Integer.parseInt(colorRules[i + 1][0]),
                        Integer.parseInt(colorRules[i + 1][1]), Integer.parseInt(colorRules[i + 1][2]));
                RuleValues rV = new RuleValues();
                rV.fromValue = from;
                rV.toValue = to;
                rV.fromColor = fromColor;
                rV.toColor = toColor;
                list.add(rV);
            } catch (NumberFormatException e) {
                e.printStackTrace();
                continue;
            }
        }

        // rule.append((dataRange[1] - rinc) + ":");
        // rule.append(colorRules[colorRules.length - 2][0] + ":"
        // + colorRules[colorRules.length - 2][1] + ":"
        // + colorRules[colorRules.length - 2][2] + " ");
        // rule.append((dataRange[1]) + ":");
        // rule.append(colorRules[colorRules.length - 1][0] + ":"
        // + colorRules[colorRules.length - 1][1] + ":"
        // + colorRules[colorRules.length - 1][2] + "\n");

    } else {
        /*
         * in this case we have also the values for the range defined
         * and the color rule has to be "v1 r1 g1 b1 v2 r2 g2 b2". 
         */
        if (colorRules[0].length != 8) {
            throw new IOException("The colortable can have records of 3 or 8 columns. Check your colortables."); //$NON-NLS-1$
        }

        for (int i = 0; i < colorRules.length; i++) {
            try {
                double from = Double.parseDouble(colorRules[i][0]);
                Color fromColor = new Color(Integer.parseInt(colorRules[i][1]),
                        Integer.parseInt(colorRules[i][2]), Integer.parseInt(colorRules[i][3]));
                double to = Double.parseDouble(colorRules[i][4]);
                Color toColor = new Color(Integer.parseInt(colorRules[i][5]),
                        Integer.parseInt(colorRules[i][6]), Integer.parseInt(colorRules[i][7]));
                RuleValues rV = new RuleValues();
                rV.fromValue = from;
                rV.toValue = to;
                rV.fromColor = fromColor;
                rV.toColor = toColor;
                list.add(rV);
            } catch (NumberFormatException e) {
                e.printStackTrace();
                continue;
            }
        }

    }
    return list;

}

From source file:de.j4velin.mapsmeasure.Util.java

/**
 * Replaces the current points on the map with the one from the provided
 * file/*from   w  w w .  ja  v  a 2  s .  c om*/
 * 
 * @param f
 *            the file to read from
 * @param m
 *            the Map activity to add the new points to
 * @throws IOException
 */
static void loadFromFile(final Uri f, final Map m) throws IOException {
    List<LatLng> list = new LinkedList<LatLng>();
    BufferedReader in = new BufferedReader(new InputStreamReader(m.getContentResolver().openInputStream(f)));
    String line;
    String[] data;
    while ((line = in.readLine()) != null) {
        data = line.split(";");
        try {
            list.add(new LatLng(Double.parseDouble(data[0]), Double.parseDouble(data[1])));
        } catch (NumberFormatException nfe) {
            // should not happen when opening a valid file
            nfe.printStackTrace();
        } catch (ArrayIndexOutOfBoundsException aiabe) {
            // should not happen when opening a valid file
            aiabe.printStackTrace();
        }
    }
    in.close();
    m.clear();
    for (int i = 0; i < list.size(); i++) {
        m.addPoint(list.get(i));
    }
}

From source file:controllers.oer.Application.java

private static int get(String parameterName, int defaultValue) {
    final String[] params = request() == null || request().queryString() == null ? null
            : request().queryString().get(parameterName);
    if (params != null)
        try {/*from   w ww .  j  av  a2  s  . c o  m*/
            return Integer.parseInt(params[0]);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            return defaultValue;
        }
    return defaultValue;
}

From source file:org.glom.web.server.Utils.java

public static void transformUnknownToActualType(final TypedDataItem dataItem, final GlomFieldType actualType) {
    if (dataItem.getType() == actualType)
        return;/*  w  ww.  j a  v a2s . c  o m*/

    String unknownText = dataItem.getUnknown();

    //Avoid repeated checks for null:
    if (unknownText == null) {
        unknownText = "";
    }

    switch (actualType) {
    case TYPE_NUMERIC:
        // TODO: Is this really locale-independent?
        double number = 0;
        if (!StringUtils.isEmpty(unknownText)) {
            try {
                number = Double.parseDouble(unknownText);
            } catch (final NumberFormatException e) {
                e.printStackTrace();
            }
        }

        dataItem.setNumber(number);
        break;
    case TYPE_TEXT:
        dataItem.setText(unknownText);
        break;
    case TYPE_DATE:
        final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = formatter.parse(unknownText);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        dataItem.setDate(date);
        break;
    case TYPE_TIME:
        /*TODO :
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
          Date date;
        try {
           date = formatter.parse(unknownText);
        } catch (ParseException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
        }
                
        setDate(date); 
        */
        break;
    case TYPE_BOOLEAN:
        final boolean bool = unknownText.equals("true");
        dataItem.setBoolean(bool); //TODO
        break;
    case TYPE_IMAGE:
        dataItem.setImageDataUrl(unknownText);
        //setImageData(null);//TODO: Though this is only used for primary keys anyway.
        break;
    case TYPE_INVALID:
        break;
    default:
        break; //TODO: Warn because this is unusual?
    }
}