Application closing unexpectedly when submitting post request

0

Well I'm developing a screen using holder view and I'm sending JSON to the server, but it's been a problem. By clicking the submit button it simply closes the application, and nothing appears in the error log.

What could be the problem? I'll put all my fragment for you to take a look at:

@EFragment(R.layout.fragment_indique_restaurante)
public class FragmentIndique extends Fragment {

@ViewById
EditText txtIndicacao;

RetornoLogin cliente;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_indique_restaurante, container, false);
    Button btnEnviar = (Button) view.findViewById(R.id.btnEnviarIndicacao);

    btnEnviar.setOnClickListener( new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            enviarIndicacao();
        }
    });

    return view;
}

@Override
public void onResume(){
    super.onResume();
    TextView toolbarTitle = (TextView) getActivity().findViewById(
            R.id.toolbar_title);
    toolbarTitle.setText(R.string.menu_recomende_restaurante);
}

public void enviarIndicacao(){

    //cliente = (RetornoLogin) getIntent().getSerializableExtra(CLIENTE);

    String txtObs = txtIndicacao.getText().toString();
   // retornoLogin.getCliente().getNomeCliente()

    try{

        //JSONObject jsonObj = new JSONObject(txtObs);
        JSONObject my_obj = new JSONObject();
        my_obj.put("titulo", "JSON x XML: a Batalha Final");
        my_obj.put("ano", 2012);
        my_obj.put("genero", "Ação");


        final AsyncHttpClient request = new AsyncHttpClient();
        request.addHeader("Authorization", Constantes.TOKEN_SERVIDOR);

        // Parametros
        RequestParams params = new RequestParams();
        params.put("cliente", my_obj);

        // Exibe a mensagem de progresso
        final ProgressDialog progress = MessageUtil.showProgress(getActivity(), R.string.aguarde, R.string.enviando_indicacao, true);
        final Context mContext = getContext();

        progress.setOnCancelListener(new DialogInterface.OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                request.cancelRequests(mContext, true);
            }
        });
        progress.show();

        request.post(Constantes.URL_CADASTRO, params,
                new AsyncHttpResponseHandler() {

                    @Override
                    public void onSuccess(String resposta) {
                        progress.dismiss();
                        sucessoResposta(resposta);
                    }

                    @Override
                    public void onFailure(Throwable t) {
                        progress.dismiss();
                        falhaResposta(t);
                    }
                });
    } catch (Exception e) {
        NegocioLog.inserir(Log.AVISO, e);
        MessageUtil.showError(getActivity(), R.string.erro_desconhecido);
    }
}

private void sucessoResposta(String resposta) {

    RetornoLogin retornoLogin;

    try {
        // Desserializa a resposta
        retornoLogin = JSONParser.parseLogin(resposta);

        // Conseguiu desserializar a resposta, verifica se houve sucesso
        if (retornoLogin.isSucesso()) {

        } else {
            // Exibe a mensagem de erro
            MessageUtil.showError(getActivity(), ResourceUtil.getString(retornoLogin.getMensagem()));
        }
    } catch (Exception e) {
        // Falha ao desserializar objeto, exibe uma mensagem
        MessageUtil.showError(getActivity(), R.string.erro_desconhecido);
        NegocioLog.inserir(Log.AVISO, e);
        return;
    }

}

private void falhaResposta(Throwable t) {
    // Envia para o servidor o log de erro
    MessageUtil.showError(getActivity(), R.string.erro_desconhecido_ws);
 }
}
    
asked by anonymous 12.05.2017 / 14:11

1 answer

2

Hello, if this is the whole code, there is an error in 'txtIndication'. It is never initialized, it is out of your try-catch, that should be why you can not capture the logs. Apparently the error is soon in this first line, which probably returns null, since it does not know its component called 'txtIndicacao'.

    
12.05.2017 / 14:50