Reputation: 3
I was trying to read the information of a Json file but there is an error that say me:
Cannot resolve method 'fromJson(android.util.JsonReader, java.lang.Class<com.proyecto.matriculas.model.Matricula>)'
I have other classes where i get the information of the file and where i did the conexion with the server, in which is the json file , and the only problem is here, in this class.
The class where i try it is:
public class GsonMatriculaParser {
public List leerFlujoJson(InputStream in) throws IOException {
Gson gson = new Gson();
JsonReader reader = new JsonReader(new InputStreamReader(in, "UTF-8"));
List<Matricula> matriculas = new ArrayList<>();
reader.beginArray();
while (reader.hasNext()) {
Matricula matricula = (Matricula) gson.fromJson(reader, Matricula.class);
matriculas.add(matricula);
}
reader.endArray();
reader.close();
return matriculas;
}
}
And the error is in gson.fromJson(reader, Matricula.class);
I'm using implementation 'com.google.code.gson:gson:2.8.5'
as my gson
depencency in my build.gradle
.
Class Matricula:
public class Matricula {
private Integer N_Registro;
private String Infraccion;
private String Fecha_Infraccion;
private String N_Matricula;
private Integer IDPropietariosFK;
public Matricula(Integer N_Registro, String Infraccion, String Fecha_Infraccion, String N_Matricula, Integer IDPropietariosFK) {
this.N_Registro = N_Registro;
this.Infraccion = Infraccion;
this.Fecha_Infraccion = Fecha_Infraccion;
this.N_Matricula = N_Matricula;
this.IDPropietariosFK = IDPropietariosFK;
}
public Integer getN_Registro() {
return N_Registro;
}
public void setN_Registro(Integer N_Registro) {
this.N_Registro = N_Registro;
}
public String getInfraccion() {
return Infraccion;
}
public void setInfraccion(String Infraccion) {
this.Infraccion = Infraccion;
}
public String getFecha_Infraccion() {
return Fecha_Infraccion;
}
public void setFecha_Infraccion(String Fecha_Infraccion) { this.Fecha_Infraccion = Fecha_Infraccion; }
public String getN_Matricula() {
return N_Matricula;
}
public void setN_Matricula(String N_Matricula) {
this.N_Matricula = N_Matricula;
}
public Integer getIDPropietariosFK() {
return IDPropietariosFK;
}
public void setIDPropietariosFK(Integer IDPropietariosFK) { this.IDPropietariosFK = IDPropietariosFK; }
}
I don't know if the problem is with the dependecy or the problem is in the code in one of my classes...
Upvotes: 0
Views: 2341
Reputation: 10881
You are using wrong JsonReader
:
android.util.JsonReader
com.google.gson.stream.JsonReader
Upvotes: 1