0
與我的Android應用NumberFormatException的android系統,parseDouble的GeoPoint
這個問題,我現在有了這個掙扎了一段時間,並通過類似的線程很多去,但從來沒有真正解決它。我沒有設法重新墜毀我自己,但我得到來自其他用戶
這裏碰撞報告是一個碰撞報告:
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)
這裏是我的代碼,最後線似乎是一個生成錯誤
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());
*編輯下面replie到@kcoppock
這可以做詭計嗎?
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());
感謝您的replie @kcoppock!認爲你是對的,我在上面編輯了我的帖子,你認爲這個修復應該足夠嗎? – Jerry
@Jerry:我可能會做類似上面的例子(我編輯了一個)。這取決於過程是否應該完全失敗,如果不能分析點,或者是否應該發生其他邏輯過程。這個例子的方法是,它試圖解析兩者,如果它們中的任何一個失敗了,它立即落到catch塊,並且不執行'new GeoPoint'行。 – kcoppock
謝謝:)看起來好多了,然後我的 – Jerry