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:control.LoadControler.java

public static List<Carte> loadCartes(String filePath) {

    File folder = new File(userPath(filePath));
    Set<File> fileSet = listFilesForFolder(folder);

    List<Carte> list = new ArrayList<>();

    for (File file : fileSet) {

        try {/*w w  w .jav  a2 s  .co m*/
            PropertiesReader ppr = new PropertiesReader(file.getCanonicalPath());
            Properties properties = ppr.readProperties();

            Carte carte = new Carte();

            try {
                carte.setNom(properties.getProperty("nom"));
                carte.setDx(Integer.parseInt(properties.getProperty("dx")));
                carte.setDy(Integer.parseInt(properties.getProperty("dy")));

                Properties ppts = new Properties();
                ppts.putAll(properties);
                ppts.remove("nom");
                ppts.remove("dx");
                ppts.remove("dy");
                carte.setProperties(ppts);

                System.out.println(carte.toString()); //DEBUG
                list.add(carte);

            } catch (NumberFormatException e) {
                e.printStackTrace();
                System.out.println("##### Erreur lors de la cration de la carte #####");
                JOptionPane.showMessageDialog(null, e);
            }
        } catch (IOException ex) {
            Logger.getLogger(LoadControler.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null, ex);
        }

    }

    return list;
}

From source file:control.LoadControler.java

public static HashMap<String, Propriete> loadProprietes(String filePath) {

    File folder = new File(userPath(filePath));
    Set<File> fileSet = listFilesForFolder(folder);

    HashMap<String, Propriete> proprieteMap = new HashMap<>();

    for (File file : fileSet) {

        try {//from  w ww.j  a v a  2 s.co  m
            PropertiesReader ppr = new PropertiesReader(file.getCanonicalPath());
            Properties properties = ppr.readProperties();

            Propriete element = new Propriete();

            try {
                String nom = new String(properties.getProperty("nom").getBytes("ISO-8859-1"), "UTF-8");
                element.setType(properties.getProperty("type"));
                element.setNom(nom);
                element.setImage(properties.getProperty("image"));
                element.setCapaciteCombat(Double.parseDouble(properties.getProperty("capaciteCombat")));
                element.setCapaciteTir(Double.parseDouble(properties.getProperty("capaciteTir")));
                element.setCapaciteDeplacement(
                        Double.parseDouble(properties.getProperty("capaciteDeplacement")));
                String description = new String(properties.getProperty("description").getBytes("ISO-8859-1"),
                        "UTF-8");
                element.setDescription(description);

                proprieteMap.put(nom.toLowerCase(), element);
                System.out.println(element.toString()); //DEBUG

            } catch (NumberFormatException e) {
                e.printStackTrace();
                System.out.println("##### Erreur lors de la cration d'une propriete #####");
                JOptionPane.showMessageDialog(null, e);
            }
        } catch (IOException ex) {
            Logger.getLogger(LoadControler.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null, ex);
        }

    }

    return proprieteMap;

}

From source file:me.acristoffers.tracker.AlarmReceiver.java

public static void setAlarm(final Context context) {
    try {//from  w ww  . ja v a 2  s.  com
        final Intent intent = new Intent(context, AlarmReceiver.class);
        final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

        final long fiveMinutes = 5 * 60 * 1000;

        final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
        final String minutes = sharedPref.getString("sync_interval", "15");

        long repeatMinutes;
        try {
            repeatMinutes = Long.parseLong(minutes) * 60 * 1000;
        } catch (NumberFormatException e) {
            repeatMinutes = 15 * 60 * 1000;
        }

        final boolean active = sharedPref.getBoolean("autosync", true);

        if (active) {
            alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, fiveMinutes, repeatMinutes,
                    pendingIntent);
        } else {
            alarmManager.cancel(pendingIntent);
        }
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
}

From source file:com.domain.java.util.IDCardUtils.java

/**
 * ??/*w w  w . ja  va2s  .  c o m*/
 * @param ca 
 * @return 
 */
public static int[] convertCharToInt(char[] ca) {

    int len = ca.length;
    int[] iArr = new int[len];
    try {
        for (int i = 0; i < len; i++) {
            iArr[i] = Integer.parseInt(String.valueOf(ca[i]));
        }
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }
    return iArr;
}

From source file:cn.wangsy.fast4j.util.IdcardUtils.java

/**
 * ??//  w  w  w.j  a  v  a2  s  .  c o m
 * 
 * @param ca
 *            
 * @return 
 */
public static int[] converCharToInt(char[] ca) {
    int len = ca.length;
    int[] iArr = new int[len];
    try {
        for (int i = 0; i < len; i++) {
            iArr[i] = Integer.parseInt(String.valueOf(ca[i]));
        }
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }
    return iArr;
}

From source file:com.mariogrip.octodroid.util.java

public static int getProgress() {
    int returnData = 0;
    double acom = 0;
    if (mainActivity.server_status) {
        JSONObject json = null;/*from  ww w  .j  av a 2s .  co  m*/
        try {
            json = new JSONObject(jsonData_job);
            JSONObject printTime_json = new JSONObject(json.getString("progress"));
            String comp = printTime_json.getString("completion");
            if (comp.equals("") || comp.equals("null")) {
                acom = 0;
            } else {
                try {
                    acom = Double.parseDouble(comp);
                } catch (NumberFormatException e) {
                    acom = 0;
                }
            }
            if (acom < 1) {
                returnData = 0;
            } else {
                returnData = (int) acom;
            }

        } catch (JSONException e) {
            e.printStackTrace();
            Log.e("OctoDroid", "printStackTrace");
        }

    }
    return returnData;
}

From source file:com.HumanDecisionSupportSystemsLaboratory.DD_P2P.Main.java

public static boolean startServers() {
    synchronized (monitorServers) {
        if (serversStarted)
            return true;
        serversStarted = true;// w ww  . j  a v a  2  s  . c om
    }
    //initial the server:
    Identity.init_Identity(false, true, false);
    System.out.println("Main: onCreateOptionsMenu: inited");
    HandlingMyself_Peer.loadIdentity(null);
    System.out.println("Main: loaded identity");

    try {
        DD.load_listing_directories();
    } catch (NumberFormatException e) {
        Log.i("server", "some error in server initial!");
        e.printStackTrace();
    } catch (UnknownHostException e) {
        Log.i("server", "some error in server initial!");
        e.printStackTrace();
    } catch (P2PDDSQLException e) {
        Log.i("server", "some error in server initial!");
        e.printStackTrace();
    }
    D_Peer myself = HandlingMyself_Peer.get_myself_or_null();
    if (myself == null) {
        Log.i("server", "Safe: startServers: no myself available!");
        //AddSafe.h Toast
        serversStarted = false;
        return false;
    } else {
        myself.cleanAddresses(true, null);
        myself.cleanAddresses(false, null);
        net.ddp2p.common.hds.Address dir0 = null;
        if (Identity.getListing_directories_addr().size() > 0)
            dir0 = Identity.getListing_directories_addr().get(0);
        else {
            String dirdd = "DIR%B%0.9.56://163.118.78.40:10000:10000:DD";
            DD_DirectoryServer ds = new DD_DirectoryServer();
            ds.parseAddress(dirdd);
            ds.save();
            dir0 = new Address(dirdd);
        }
        dir0.pure_protocol = net.ddp2p.common.hds.Address.DIR;
        dir0.branch = DD.BRANCH;
        dir0.agent_version = DD.VERSION;
        dir0.certified = true;
        dir0.version_structure = net.ddp2p.common.hds.Address.V3;
        dir0.address = dir0.domain + ":" + dir0.tcp_port;
        System.out.println("Adding address: " + dir0);
        myself.addAddress(dir0, true, null);
        System.out.println("Myself After Adding address: " + myself);
        Log.i("myself", myself.toString());

        try {
            DD.startUServer(true, Identity.current_peer_ID);
            DD.startServer(false, Identity.current_peer_ID);
            DD.startClient(true);

        } catch (NumberFormatException e) {
        } catch (P2PDDSQLException e) {
            System.err.println("Safe: onCreateView: error");
            e.printStackTrace();
        }

        Log.i("Test peer", "test peer...");
    }
    //initial chat:
    try {
        net.ddp2p.common.plugin_data.PluginRegistration.loadPlugin(
                com.HumanDecisionSupportSystemsLaboratory.DD_P2P.AndroidChat.Main.class,
                HandlingMyself_Peer.getMyPeerGID(), HandlingMyself_Peer.getMyPeerName());
        com.HumanDecisionSupportSystemsLaboratory.DD_P2P.AndroidChat.Main.receiver = new AndroidChatReceiver();
    } catch (MalformedURLException e) {
        Log.i("chat", "some error in chat initial!");
        e.printStackTrace();
    }
    return true;
}

From source file:ly.count.android.sdk.CrashDetails.java

private static long getTotalRAM() {
    if (totalMemory == 0) {
        RandomAccessFile reader = null;
        String load = null;/*from w  ww.  j ava 2  s.  co  m*/
        try {
            reader = new RandomAccessFile("/proc/meminfo", "r");
            load = reader.readLine();

            // Get the Number value from the string
            Pattern p = Pattern.compile("(\\d+)");
            Matcher m = p.matcher(load);
            String value = "";
            while (m.find()) {
                value = m.group(1);
            }
            try {
                totalMemory = Long.parseLong(value) / 1024;
            } catch (NumberFormatException ex) {
                totalMemory = 0;
            }
        } catch (IOException ex) {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException exc) {
                exc.printStackTrace();
            }
            ex.printStackTrace();
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException exc) {
                exc.printStackTrace();
            }
        }
    }
    return totalMemory;
}

From source file:org.multibit.utils.CSMiscUtils.java

public static BigInteger getRawUnitsFromDisplayString(CSAsset asset, String display) {
    BigDecimal result = null;//from  www  .j  a v a  2 s  .  c  o m
    try {
        //System.out.println("Start to get raw units from: " + display);
        result = new BigDecimal(display);
    } catch (NumberFormatException nfe) {
        nfe.printStackTrace();
        return null;
    }

    // Reverse apply the multiple
    int decimalPlaces = CSMiscUtils.getNumberOfDisplayDecimalPlaces(asset);
    if (decimalPlaces != 0) {
        result = result.movePointRight(decimalPlaces);
    }
    // FIXME: what if multiple is 0.0? ignore? error?
    //   double multiple = asset.getMultiple();
    //   BigDecimal m = new BigDecimal(String.valueOf(multiple));
    //   result = result.divide(m, MathContext.DECIMAL32);

    //System.out.println("multiplier=" + m + ", removed multiplier =" + display);

    double interestRate = asset.getInterestRate();

    BigDecimal rate = new BigDecimal(String.valueOf(interestRate));
    rate = rate.divide(new BigDecimal(100));
    rate = rate.add(BigDecimal.ONE);

    Date issueDate = asset.getIssueDate();
    DateTime d1 = new DateTime(issueDate);
    DateTime d2 = new DateTime();
    int seconds = Math.abs(Seconds.secondsBetween(d1, d2).getSeconds());

    //System.out.println("...Number of seconds difference: " + seconds);

    BigDecimal elapsedSeconds = new BigDecimal(seconds);
    BigDecimal elapsedYears = elapsedSeconds.divide(new BigDecimal(COINSPARK_SECONDS_IN_YEAR),
            MathContext.DECIMAL32);
    //System.out.println("...Number of years difference: " + elapsedYears.toPlainString());

    double base = elapsedSeconds.doubleValue();
    double exp = elapsedYears.doubleValue();
    //System.out.println("...base=" + base + "  exponent=" + exp);
    double interestMultipler = Math.pow(rate.doubleValue(), elapsedYears.doubleValue());

    //System.out.println("interest multipler =" + interestMultipler);

    result = result.divide(new BigDecimal(String.valueOf(interestMultipler)), MathContext.DECIMAL32);

    //System.out.println("result = " + result.toPlainString());

    result = result.setScale(0, RoundingMode.DOWN);
    result = result.stripTrailingZeros();

    //System.out.println("result floored = " + result.toPlainString());

    String resultString = result.toPlainString();
    return new BigInteger(resultString);
}

From source file:com.xhsoft.framework.common.utils.ClassUtil.java

/**
 * //w  w  w  . j  a  v a 2s .c  o  m
 * @return - String
 * @author: lizj
 */
public static String getCallerName(int depth) {
    String JDK_VERSION = System.getProperty("java.version");

    double version = 1.3D;

    try {
        JDK_VERSION = JDK_VERSION.substring(0, 3);

        version = Double.parseDouble(JDK_VERSION);
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }

    if (DEBUG) {
        log.debug("java.version: " + version);
    }

    if (version >= 1.5D) {
        try {
            Thread currentThread = Thread.currentThread();

            StackTraceElement[] stack = (StackTraceElement[]) (Thread.class
                    .getMethod("getStackTrace", new Class[0]).invoke(currentThread, new Object[0]));

            if (stack != null && stack.length >= 3) {
                for (int i = 0; i < stack.length; i++) {
                    if (stack[i].getClassName().equals(ClassUtil.class.getName())
                            && "getCallerName".equals(stack[i].getMethodName())) {
                        if (i + 2 + depth < stack.length) {
                            return stack[i + 2 + depth].getClassName() + "."
                                    + stack[i + 2 + depth].getMethodName();
                        }
                    }
                }

                return null;
            }
        } catch (IllegalArgumentException e1) {
            e1.printStackTrace();
        } catch (SecurityException e1) {
            e1.printStackTrace();
        } catch (IllegalAccessException e1) {
            e1.printStackTrace();
        } catch (InvocationTargetException e1) {
            e1.printStackTrace();
        } catch (NoSuchMethodException e1) {
            e1.printStackTrace();
        }
    } else if (version >= 1.4D) {
        StackTraceElement[] stack = (new Throwable()).getStackTrace();

        if (stack != null && stack.length >= (3 + depth)) {
            return stack[2 + depth].getClassName() + "." + stack[2 + depth].getMethodName();
        }
    }

    java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream(4096);

    new Throwable().printStackTrace(new java.io.PrintStream(bos));

    String x = bos.toString();

    java.io.BufferedReader br = new java.io.BufferedReader(new java.io.StringReader(x));

    String val = null;
    String str = null;

    try {
        int i = 0;

        while ((str = br.readLine()) != null) {
            if (i++ == (3 + depth)) {
                str = StringUtil.getA5(str, "at ");

                val = str = StringUtil.getB4(str, "(");
            }
        }
    } catch (IOException e) {
    }

    return val;
}