作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我已经为此苦苦挣扎了一段时间,对我来说,我看不出为什么 -0. 086167157 不是有效的 double 值。我只是想将从 API 调用返回的字符串值转换为 double 值(经度值)
这是错误信息:
java.lang.NumberFormatException: For input string: "-0.086167157"
W/System.err: at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1306)
W/System.err: at java.lang.Double.parseDouble(Double.java:547)
W/System.err: at com.google.gson.stream.JsonReader.nextDouble(JsonReader.java:909)
W/System.err: at com.google.gson.Gson$2.read(Gson.java:284)
W/System.err: at com.google.gson.Gson$2.read(Gson.java:278)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
W/System.err: at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
W/System.err: at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
W/System.err: at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
W/System.err: at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:37)
W/System.err: at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:25)
W/System.err: at retrofit2.ServiceMethod.toResponse(ServiceMethod.java:119)
W/System.err: at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:218)
W/System.err: at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:112)
W/System.err: at okhttp3.RealCall$AsyncCall.execute(RealCall.java:153)
W/System.err: at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
W/System.err: at java.lang.Thread.run(Thread.java:762)
/
@Parcel(implementations = { LocationRealmProxy.class },
value = Parcel.Serialization.BEAN,
analyze = {Location.class})
public class Location extends RealmObject {
@PrimaryKey
@SerializedName("id")
int locationId;
@SerializedName("company_id")
int companyId;
@SerializedName("company_name")
String companyName;
@SerializedName("logo")
String logo;
@SerializedName("address_one")
String addressOne;
@SerializedName("address_two")
String addressTwo;
@SerializedName("address_three")
String addressThree;
@SerializedName("town")
String town;
@SerializedName("county")
String county;
@SerializedName("postcode")
String postcode;
@SerializedName("country")
String country;
@SerializedName("latitude")
Double latitude;
@SerializedName("longitude")
Double longitude;
@SerializedName("venue_type")
String venueType;
@SerializedName("type")
String type;
@SerializedName("added_date")
String addedDate;
@SerializedName("modified_date")
String modifiedDate;
@SerializedName("archived_date")
String archivedDate;
@SerializedName("status")
String status;
@SerializedName("map_thumbnail")
String mapThumbnail;
@SerializedName("venue_type_id")
int venueTypeId;
public Location(){
}
public Location(int locationId, int companyId, String companyName, String logo, String addressOne, String addressTwo, String addressThree,
String town, String county, String postcode, String country, Double latitude, Double longitude, String venueType, String type,
String addedDate, String modifiedDate, String archivedDate, String status, String mapThumbnail, int venueTypeId) {
this.locationId = locationId;
this.companyId = companyId;
this.companyName = companyName;
this.logo = logo;
this.addressOne = addressOne;
this.addressTwo = addressTwo;
this.addressThree = addressThree;
this.town = town;
this.county = county;
this.postcode = postcode;
this.country = country;
this.latitude = latitude;
this.longitude = longitude;
this.venueType = venueType;
this.type = type;
this.addedDate = addedDate;
this.modifiedDate = modifiedDate;
this.archivedDate = archivedDate;
this.status = status;
this.mapThumbnail = mapThumbnail;
this.venueTypeId = venueTypeId;
}
//Getters and setters
/
@GET(NetworkConstants.LOCATIONS_ENDPOINT)
Call<LocationsResponse> getAllLocations(@Header("api-token") String token);
我正在使用 Gson 进行网络调用改造
最佳答案
您的字符串在句号之后有一个不可见的非打印字符。复制并粘贴到十六进制转储,您会看到:
00000000 2d 30 2e e2 80 8e 30 38 36 31 36 37 31 35 37 |-0....086167157|
好像是一个left-to-right mark
解决方法:在API中修复。客户端没有理由过滤输入中的垃圾数字。
关于android - java.lang.NumberFormatException : For input string: "-0.086167157" 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49800498/
我是一名优秀的程序员,十分优秀!