J'essaie d'utiliser retrofit 2 dans mon application et je reçois l'erreur de folloing:Android + 2 + Retrofit GSON = Impossible d'invoquer sans args constructeur pour l'interface
java.lang.RuntimeException: Unable to invoke no-args constructor for interface box.gov.br.ourapp.API.ClientePFApi. Register an InstanceCreator with Gson for this type may fix this problem.
Et. .. Je ne sais pas où est le problème =/
Ma classe java:
public class ClientePFVisao360 {
private static final long serialVersionUID = 3182722297876508581L;
@SerializedName("txCPF")
@Expose
public String txCPF;
@SerializedName("nuCocli")
@Expose
public Long nuCocli;
@SerializedName("txNomeCliente")
@Expose
public String txNomeCliente;
@SerializedName("dtNascimento")
@Expose
public String dtNascimento;
@SerializedName("dtInicioRelacionamento")
@Expose
public String dtInicioRelacionamento;
@SerializedName("txSegmento")
@Expose
public String txSegmento;
@SerializedName("txOcupacao")
@Expose
public String txOcupacao;
@SerializedName("txSexo")
@Expose
public String txSexo;
@SerializedName("txEstadoCivil")
@Expose
public String txEstadoCivil;
@SerializedName("txNivelInstrucao")
@Expose
public String txNivelInstrucao;
@SerializedName("txTipoPessoa")
@Expose
public String txTipoPessoa;
@SerializedName("nuNacionalidade")
@Expose
public Integer nuNacionalidade;
@SerializedName("txNaturalidade")
@Expose
public String txNaturalidade;
@SerializedName("txNomePai")
@Expose
public String txNomePai;
@SerializedName("txNomeMae")
@Expose
public String txNomeMae;
@SerializedName("txDeficiencia")
@Expose
public String txDeficiencia;
@SerializedName("nichos")
@Expose
public List<String> nichos;
@SerializedName("conjuge")
@Expose
public Conjuge conjuge;
@SerializedName("renda")
@Expose
public Renda renda;
@SerializedName("meiosComunicacao")
@Expose
public MeioComunicacao meiosComunicacao;
@SerializedName("carteiraGRC")
@Expose
public List<CarteiraGrc> carteiraGRC;
//getters and setters....
public ClientePFVisao360() {
}
Mon Interface:
public interface ClientePFApi {
@GET("clientepf/{user}")
Call<ClientePFApi> getClientePF(@Path("user") String user);
}
Comment j'appelle ceci:
OkHttpClient okClient = new OkHttpClient();
Retrofit client = new Retrofit.Builder()
.baseUrl(API)
.client(okClient)
.addConverterFactory(GsonConverterFactory.create())
.build();
ClientePFApi service = client.create(ClientePFApi.class);
Call<ClientePFApi> call = service.getClientePF("bigua");
call.enqueue(new Callback<ClientePFApi>() {
@Override
public void onResponse(@NonNull Call<ClientePFApi> call, @NonNull Response<ClientePFApi> response) {
Log.e("retrofit", "ok");
}
@Override
public void onFailure(@NonNull Call<ClientePFApi> call, @NonNull Throwable t) {
Log.e("trow", t.toString());
Log.e("retrofit", "crash");
}
});
Le JSON je suis reçu de mon API:
{"txCPF":"1234567","nuCocli":12345,"txNomeCliente":"bla","dtNascimento":"12/11/1984","dtInicioRelacionamento":"04/05/2010","txSegmento":"bla","txOcupacao":"bla","txSexo":"bla","txEstadoCivil":"bla","txNivelInstrucao":"bla","txTipoPessoa":"bla","nuNacionalidade":null,"txNaturalidade":"DF","txNomePai":"blah","txNomeMae":"bla","txDeficiencia":null,"nichos":null,"conjuge":null,"renda":null,"meiosComunicacao":null,"carteiraGRC":null}
Je suis désolé si son problème Noob/question, mais je J'ai lu beaucoup de questions ici et je ne comprends pas où est mon erreur.
grâce à des conseils pour toute aide.
Oh ... Je vois ..., a changé et l'erreur a changé aussi, mais il semble que le JSON sa mauvaise formated, nouvelle erreur: com. google.gson.JsonSyntaxException: java.lang.IllegalStateException: attendu BEGIN_ARRAY mais était STRING à la ligne 1 colonne 499 chemin $ .nichos –
Cette erreur car dans votre classe 'ClientePFVisao360'' nichos' et 'carteiraGRC' est objet Liste et dans votre' Json' contient 'null' pour cette clé. Pour résoudre ceci, vous devez effacer le tableau '[]' à la place de 'null' pour cette clé. –