0

Couldn't get any data in return onResponse, the result skipped to onFailure.

It works on my other application, data is return and displayed successfully, but the same thing failed on this application.

I tried with other code and still couldn't find out the problem, not a single error message show, any idea?

private void parseJSON() {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Api.URL_DATA)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        Api api = retrofit.create(Api.class);

        Call<List<ListItem>> call = api.getList();

        call.enqueue(new Callback<List<ListItem>>() {
            @Override
            public void onResponse(Call<List<ListItem>> call, retrofit2.Response<List<ListItem>> response) {
                if (response.isSuccessful()) {
                    Toast.makeText(getApplicationContext(), "Server returned data", Toast.LENGTH_SHORT).show();
                    DeveloperList = response.body();

                    listAdapter.setList(DeveloperList);
                    progressDialog.hide();

                }
                else {
                    Toast.makeText(getApplicationContext(), "Server returned an error", Toast.LENGTH_SHORT).show();
                }

            }

            @Override
            public void onFailure(Call<List<ListItem>> call, Throwable t) {
                progressDialog.hide();
                Toast.makeText(getApplicationContext(), "This is an actual network failure...", Toast.LENGTH_SHORT).show();
            }
        });
    }
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Brandon
  • 15
  • 4
  • Have you given [internet permission](https://stackoverflow.com/questions/2169294/how-to-add-manifest-permission-to-an-application) in the manifest file? – Higanbana Jun 14 '19 at 06:30
  • try to enable logging and check do it actually has the data in the same format what you have created models for check this for enabling logging https://stackoverflow.com/questions/40815081/how-to-get-retrofit-callback-get-response-body-in-json-formate/40815569#40815569 – Madhur Jun 14 '19 at 07:01
  • in `onfailure` print your `Throwable t` error message. – Tejas Pandya Jun 14 '19 at 07:12
  • Throwable t: java.lang.NumberFormatException:For input string: "$2,680.86" – Brandon Jun 14 '19 at 08:07
  • this means that you are trying to convert a string which cant be converted to a number(integer/double). Remove the $ character before doing the conversion. – uneq95 Jun 14 '19 at 08:19
  • @uneq95 Sorry for late reply. This problem was solved, thanks for your answer! Can you post the answer as a new answer so that I can check my question as answered? Thanks again – Brandon Jul 13 '19 at 19:58

1 Answers1

0

You are trying to convert a string which can't be converted to a number(integer/double). Remove the $ character before doing the conversion.

uneq95
  • 2,158
  • 2
  • 17
  • 28