I run this code and have crash. Do you can help me?
public class RepairCostsData {
@Expose
private int month;
@Expose
private int month_id;
@Expose
private int year;
@Expose
private double summa;
@Expose
private double detail_price;
@Expose
private double job_price;
...
Call Gson().fromJson() for this class
RepairCostsData[] repairCostsData = new Gson().fromJson(jsonObject.getJSONArray(DATA).toString(),
RepairCostsData[].class);
**JSON from server **
[{"month":"","month_id":"3","year":"2014","detail_price":0,"job_price":0,"summa":0},{"month":"","month_id":"4","year":"2014","detail_price":0,"job_price":0,"summa":0},{"month":"","month_id":"5","year":"2014","detail_price":0,"job_price":0,"summa":0},{"month":"","month_id":"6","year":"2014","detail_price":0,"job_price":0,"summa":0},{"month":"Июль","month_id":"7","year":"2014","detail_price":"250.00","job_price":0,"summa":250},{"month":"","month_id":"8","year":"2014","detail_price":0,"job_price":0,"summa":0}]
Logs
com.google.gson.JsonSyntaxException: java.lang.NumberFormatException:
Invalid double: ""
at com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:232)
at com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:222)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
at com.google.gson.internal.bind.ArrayTypeAdapter.read(ArrayTypeAdapter.java:72)
at com.google.gson.Gson.fromJson(Gson.java:791)
at com.google.gson.Gson.fromJson(Gson.java:757)
at com.google.gson.Gson.fromJson(Gson.java:706)
at com.google.gson.Gson.fromJson(Gson.java:678)
at com.DriverNotes.AndroidMobileClientTest.model.server.statistics.RepairCosts.<init>(RepairCosts.java:29)
at com.DriverNotes.AndroidMobileClientTest.model.server.statistics.RepairCostsStatistics.<init>(RepairCostsStatistics.java:20)
at com.DriverNotes.AndroidMobileClientTest.network.VolleyServerConnector$48$1.run(VolleyServerConnector.java:780)
at java.lang.Thread.run(Thread.java:856)
Crash in this line:
RepairCostsData[] repairCostsData = new Gson().fromJson(jsonObject.getJSONArray(DATA).toString(),
RepairCostsData[].class);
"job_price":"0.00" is not a double but a string,
change to
"job_price": 0.00
private int month;
and
"month":"Июль"
also do not match
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With