0
I’m kind of new to java and I’m trying to create an application where I call server data and fill an object, but the object is not filled, whenever I call the object all attributes are null.
The server data call function is this:
public void preencherObj(Context context, final Aplicativo aplicativo){
try{
Ion.with(context)
.load(Constantes.url)
.setBodyParameter("id_empresa", String.valueOf(Constantes.id_empresa))
.setBodyParameter("acao", "B")
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
@Override
public void onCompleted(Exception e, JsonObject result) {
aplicativo.setId_aplicativo(result.get("id_aplicativo").getAsInt());
aplicativo.setNm_cor(result.get("nm_cor").getAsString());
aplicativo.setNr_telefone(result.get("nr_telefone").getAsString());
aplicativo.setNr_telefone2(result.get("nr_telefone2").getAsString());
aplicativo.setUrl_logo(result.get("url_logo").getAsString());
aplicativo.setUrl_whats(result.get("url_whats").getAsString());
aplicativo.setUrl_local(result.get("url_local").getAsString());
aplicativo.setUrl_site(result.get("url_site").getAsString());
aplicativo.setNm_endereco(result.get("nm_endereco").getAsString());
aplicativo.setNm_cidade(result.get("nm_cidade").getAsString());
aplicativo.setNm_estado(result.get("nm_estado").getAsString());
aplicativo.setCd_cep(result.get("cd_cep").getAsString());
aplicativo.setUrl_app(result.get("url_app").getAsString());
aplicativo.setNm_empresa(result.get("nm_empresa").getAsString());
aplicativo.setUrl_logo_splash(result.get("url_logo_splash").getAsString());
}
});
}catch (Exception e){
Metodos.ShowPopup(context);
}
}
Could anyone tell me why the object always returns null after the function call?
Try to take that reserved word
final
in the definition of the method and test again– Ezequiel Martinez
Did you try to rescue the attributes before
.setCallback()
arrow them? Yeah.setCallback()
is asynchronous.– Emerson Barcellos