gpt4 book ai didi

android - java.lang.NumberFormatException : For input string: "-0.‎086167157" 异常

转载 作者:行者123 更新时间:2023-11-29 14:59:46 26 4
gpt4 key购买 nike

所以我已经为此苦苦挣扎了一段时间,对我来说,我看不出为什么 -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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com