Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gson .JsonSyntaxException - java.lang.NumberFormatException: Invalid double: ""

Tags:

json

android

gson

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);
like image 774
Artem Avatar asked Aug 05 '14 13:08

Artem


2 Answers

"job_price":"0.00" is not a double but a string,

change to

"job_price": 0.00
like image 176
Decoy Avatar answered Nov 11 '22 16:11

Decoy


private int month;

and

"month":"Июль"

also do not match

like image 34
injecteer Avatar answered Nov 11 '22 15:11

injecteer