Having this problem with my android app
I struggled with this for some time now, and went through alot of similar threads but never really solved it. I haven’t managed to recreate the crash my self but i get crash-reports from other users
Here is a crash-report:
java.lang.NumberFormatException: -
at org.apache.harmony.luni.util.FloatingPointParser.initialParse(FloatingPointParser.java:149)
at org.apache.harmony.luni.util.FloatingPointParser.parseDouble(FloatingPointParser.java:281)
at java.lang.Double.parseDouble(Double.java:318)
at polis.koll.HelloMapView.loadallmarkers(HelloMapView.java:665)
at polis.koll.HelloMapView.access$10(HelloMapView.java:611)
at polis.koll.HelloMapView$6.run(HelloMapView.java:587)
at java.lang.Thread.run(Thread.java:1027)
And here is my code, the last line seem to be to one generating the error
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
/** Send URL to parse XML Tags */
URL sourceUrl = new URL(
"http://www.mysite.com/xml.php");
/** Create handler to handle XML Tags ( extends DefaultHandler ) */
MyXMLHandler myXMLHandler = new MyXMLHandler();
xr.setContentHandler(myXMLHandler);
xr.parse(new InputSource(sourceUrl.openStream()));
} catch (Exception e) {
//System.out.println("XML Pasing Excpetion = " + e);
}
sitesList = MyXMLHandler.sitesList;
gotsnr = "";
gotmarkers = 0;
LocationOverlay locationOverlay = new LocationOverlay(mapView, getResources().getDrawable(R.drawable.polis), mContext);
if (sitesList !=null){
for (int i = 0; i < sitesList.getSnr().size(); i++) {
gotsnr = sitesList.getSnr().get(i);
gotmarkers = (i);
//if (gotsnr !=""){
if (sitesList.getLat().get(i).equalsIgnoreCase("")||sitesList.getLat().get(i).equalsIgnoreCase(null)){
// Empty, do nothing
} else{
GeoPoint point = new GeoPoint( new Double(Double.parseDouble(sitesList.getLat().get(i)) * 1e6).intValue() , new Double(Double.parseDouble(sitesList.getLng().get(i)) * 1e6).intValue());
* Edit below in replie to @kcoppock
Could this do the trick?
double dlat = 0;
double dlng = 0;
if (sitesList.getLat().get(i) !=null && !"".equals(sitesList.getLat().get(i)) ){
try {
dlat = Double.parseDouble(sitesList.getLat().get(i));
} catch (NumberFormatException e) {
//System.out.println(e.getMessage());
}
}
if (sitesList.getLng().get(i) !=null && !"".equals(sitesList.getLng().get(i)) ){
try {
dlng = Double.parseDouble(sitesList.getLng().get(i));
} catch (NumberFormatException e) {
//System.out.println(e.getMessage());
}
}
if (dlat !=0 && dlng !=0){
GeoPoint point = new GeoPoint( new Double(dlat * 1e6).intValue() , new Double(dlng * 1e6).intValue());
You’re not handling the
NumberFormatExceptionin the first place, which is bad practice even if you weren’t having crashes. Split that line up, parse the doubles first, and be sure to catch theNumberFormatExceptionand handle it appropriately (e.g. throw an alert dialog, place a default value, etc.) in case for some reason the value ingetLat()orgetLon()are not parseable, which is what is apparently happening in these cases.