0

Obtaining JSON from an external source and trying to parse it with GSON, I'm getting the above mentioned error. Here's my main activity:

final ProgressDialog dialog;

        dialog = new ProgressDialog(PlayerDetailsActivity.this);
        dialog.setTitle(getString(R.string.string_getting_json_title));
        dialog.setMessage(getString(R.string.string_getting_json_message));
        dialog.show();

        ApiService api = RetroClient.getApiService();

        Call<PlayerRolesList> call = api.getMyJSON();

        call.enqueue(new Callback<PlayerRolesList>() {
            @Override
            public void onResponse(Call<PlayerRolesList> call, Response<PlayerRolesList> response) {
                //Dismiss Dialog
                dialog.dismiss();

                if(response.isSuccessful()) {
                    /**
                     * Got Successfully
                     */
                    Toast.makeText(PlayerDetailsActivity.this, "Successful", Toast.LENGTH_LONG).show();
                    alPlayerRoles = response.body().getPlayerRoles();

                    /**
                     * Binding that List to Adapter
                     */
                    adapter = new PlayerDetailsAdapter(PlayerDetailsActivity.this, alPlayerRoles);
                    lvPlayerRoles.setAdapter(adapter);

                } else {
                    Toast.makeText(PlayerDetailsActivity.this, response.message(), Toast.LENGTH_LONG).show();
                }
            }

That's the code where the request is made and the layout is supposed to be populated with the adapter.

Here's the model class too:

public class PlayerRolesList {

    @SerializedName("data")
    @Expose
    private ArrayList<PlayerRolesModel> players = new ArrayList<>();

    /**
     * @return The contacts
     */
    public ArrayList<PlayerRolesModel> getPlayerRoles() {
        return players;
    }

    /**
     * @param players The player roles
     */
    public void setPlayerRoles(ArrayList<PlayerRolesModel> players) {
        this.players = players;
    }
}

I've done the whole thing according to this tutorial http://www.pratikbutani.com/2016/05/android-tutorial-json-parsing-using-retrofit-part-1/

Running his app works fine, but mine doesn't seem to agree with the JSON for some reason and I'm not sure where I'm making the mistake.

What are the common reasons for this error message?

user1938007
  • 459
  • 1
  • 5
  • 14
  • At the risk of sounding even dumber, can you elaborate on that more specifically? Does that mean that the external JSON file that I'm loading is not in the correct format? – user1938007 Jun 28 '17 at 21:02
  • Yes, or at least it doesn't match your model fx `class class1 { public class2 results;}` and json looks like `{"results":"aaa"}` instead `{"results":{}}` – Selvin Jun 28 '17 at 21:06

0 Answers0