handle number format exception
when i am getting data after xml parsing and use it in my application i am getting number format exception so i add try and catch block between that code and now it is not force close but the problem is that after getting the exception it does not execute the code after that how to get over again and it takes some default value for it and execute for next my code is below pls modify in my catch block...
for(int i=0;i<sitesList.getLatitude().size();i++)
{
if(sitesList.getType().get(i).equalsIgnoreCase("Galerías Online"))
{
name = sitesList.getLatitude().get(i);
name1 = sitesList.getLongitude().get(i);
GeoPoint point5 = new GeoPoint((int) (Double.parseDouble(name) * 1E6),
(int) (Double.parseDouble(name1) * 1E6));
OverlayItem overlayItem4 = new OverlayItem(point5, sitesList.getGalleryname().get(i)+ "--"+
sitesList.getAddress().get(i),sitesList.getImagesurl().get(i)+ "--"+sitesList.getEmail().get(i)+ "--"+
sitesList.getPhoneno().get(i)+ "--"+sitesList.getWeb().get(i) );
itemizedOverlay3.addOverlay(overlayItem4);
}
}
}catch (NumberFormatException e) {
}
means it continue for l开发者_如何学JAVAoop after getting exception and use default value in place of exception..i am getting exception here name = sitesList.getLatitude().get(i); name1 = sitesList.getLongitude().get(i);and i want to continue after exception how to do this ..i am new in java
If you are getting null or empty values in your tag then, modify your code like this:
if(sitesList.getType().get(i).equalsIgnoreCase("Galerías Online"))
{
name = sitesList.getLatitude().get(i);
name1 = sitesList.getLongitude().get(i);
if(name.equalsIgnoreCase("")||name.equalsIgnoreCase(null))
{
name=// your default longitude or latitude
}
if(name1.equalsIgnoreCase("")||name1.equalsIgnoreCase(null))
{
name1=// your default longitude or latitude
}
....
}
hope it helps
for(int i=0;i<sitesList.getLatitude().size();i++)
{
if(sitesList.getType().get(i).equalsIgnoreCase("Galerías Online"))
{
name = sitesList.getLatitude().get(i);
name1 = sitesList.getLongitude().get(i);
GeoPoint point5 = new GeoPoint( (Double.parseDouble(name) * 1E6),
(Double.parseDouble(name1) * 1E6));
OverlayItem overlayItem4 = new OverlayItem(point5, sitesList.getGalleryname().get(i)+ "--"+
sitesList.getAddress().get(i),sitesList.getImagesurl().get(i)+ "--"+sitesList.getEmail().get(i)+ "--"+
sitesList.getPhoneno().get(i)+ "--"+sitesList.getWeb().get(i) );
itemizedOverlay3.addOverlay(overlayItem4);
}
}
}catch (NumberFormatException e) {
}
its because u r casting Double to Int...
精彩评论