[英]Why does the return value of getCurrentLattitude() throws number format exception?
I have tried something like below 我已经尝试过以下内容
double latitude = 0;
double longitude = 0;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.places_details_gridview);
locManager = (LocationManager) getSystemService(LOCATION_SERVICE);
currentLoc = new CurrentLocation(locManager, ShowPlacesInList.this);
if(currentLoc.getCurrentLattitude() != null && currentLoc.getCurrentLongitude() != null){
latitude = Double.parseDouble(currentLoc.getCurrentLattitude());
longitude = Double.parseDouble(currentLoc.getCurrentLongitude());
myLoc = new Location("");
myLoc.setLatitude(latitude);
myLoc.setLongitude(longitude);
calculateDist();
}
}
It showing number format exception in the 它在
latitude = Double.parseDouble(currentLoc.getCurrentLattitude());
from currentLoc.getLatitude and currentloc.getLongitude i am getting a string value 从currentLoc.getLatitude和currentloc.getLongitude我正在获取一个字符串值
from currentLoc.getLatitude and currentloc.getLongitude i am getting a string value
从currentLoc.getLatitude和currentloc.getLongitude我正在获取一个字符串值
What string value? 什么字符串值?
The parseDouble method throws a NumberFormatException when "the string does not contain a parsable double" - http://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#parseDouble(java.lang.String) 当“字符串不包含可分析的双精度数”时,parseDouble方法将引发NumberFormatException- http ://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#parseDouble(java.lang 。串)
The NumberFormatException that is thrown will show you exactly what the problem is eg: 引发的NumberFormatException将向您确切显示问题所在,例如:
java.lang.NumberFormatException: For input string: "A5.0"
java.lang.NumberFormatException:对于输入字符串:“ A5.0”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.