Я пытаюсь получить некоторые значения от модернизации. Я получаю ответ 200, но когда я пытаюсь распечатать эту информацию, я получаю on a null object reference
. Я не понимаю этого, потому что я получаю ответ для ввода OnSuccessfull, но, наконец, при печати данных выдает ошибку. Это метод:
public void getAllParticipantByGroup(String id_group){
Call<ParticipantResponse> call = APIService.getParticipantsByGroup(id_group);
call.enqueue(new Callback<ParticipantResponse>() {
@Override
public void onResponse(Call<ParticipantResponse> call, Response<ParticipantResponse> response) {
if (response.isSuccessful()) {
participantResponse = response.body();
Log.d("VALUE",String.valueOf(participantResponse.getParticipant().getId()));
Log.d("RESPONSE_SUCCESS", "Everything All right");
}
}
@Override
public void onFailure(Call<ParticipantResponse> call, Throwable t) {
Log.d("RESPONSE_FAILURE", String.valueOf(t));
}
});
}
Это ОК.
2020-04-22 16:31:20.594 6001-6033/com.example.karate_manager D/OkHttp: --> GET http://111.111.11.1/trabajos/api-manager-karate/karate-manager-api-laravel/public/api/participant/getall/4
2020-04-22 16:31:20.594 6001-6033/com.example.karate_manager D/OkHttp: --> END GET
2020-04-22 16:31:20.733 6001-6033/com.example.karate_manager D/OkHttp: <-- 200 OK http://111.111.11.1/trabajos/api-manager-karate/karate-manager-api-laravel/public/api/participant/getall/4 (138ms)
2020-04-22 16:31:20.733 6001-6033/com.example.karate_manager D/OkHttp: Date: Wed, 22 Apr 2020 14:31:20 GMT
2020-04-22 16:31:20.733 6001-6033/com.example.karate_manager D/OkHttp: Server: Apache/2.4.38 (Win64) OpenSSL/1.1.1b PHP/7.3.3
2020-04-22 16:31:20.733 6001-6033/com.example.karate_manager D/OkHttp: X-Powered-By: PHP/7.3.3
2020-04-22 16:31:20.733 6001-6033/com.example.karate_manager D/OkHttp: Cache-Control: no-cache, private
2020-04-22 16:31:20.733 6001-6033/com.example.karate_manager D/OkHttp: X-RateLimit-Limit: 60
2020-04-22 16:31:20.733 6001-6033/com.example.karate_manager D/OkHttp: X-RateLimit-Remaining: 56
2020-04-22 16:31:20.733 6001-6033/com.example.karate_manager D/OkHttp: Content-Length: 1376
2020-04-22 16:31:20.733 6001-6033/com.example.karate_manager D/OkHttp: Keep-Alive: timeout=5, max=98
2020-04-22 16:31:20.733 6001-6033/com.example.karate_manager D/OkHttp: Connection: Keep-Alive
2020-04-22 16:31:20.733 6001-6033/com.example.karate_manager D/OkHttp: Content-Type: application/json
2020-04-22 16:31:20.734 6001-6033/com.example.karate_manager D/OkHttp: {"code":200,"participants":[{RESPOSE ARRAY"}
2020-04-22 16:31:20.734 6001-6033/com.example.karate_manager D/OkHttp: <-- END HTTP (1376-byte body)
2020-04-22 16:31:20.790 6001-6001/com.example.karate_manager E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.karate_manager, PID: 6001
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.example.karate_manager.Models.ParticipantModel.Participant.getId()' on a null object reference
at com.example.karate_manager.Fragments.ScoringFragment$1.onResponse(ScoringFragment.java:63)
at ...
Это участникResponse
public class ParticipantResponse {
private float code;
private Participant participant;
private ArrayList<Participant > participants = new ArrayList <> ();
private ArrayList<Karateka > karateka = new ArrayList <> ();
private String msg;
public float getCode() {
return code;
}
public void setCode(float code) {
this.code = code;
}
public Participant getParticipant() {
return participant;
}
public void setParticipant(Participant participant) {
this.participant = participant;
}
public ArrayList<Karateka> getKarateka() {
return karateka;
}
public void setKarateka(ArrayList<Karateka> karateka) {
this.karateka = karateka;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public ParticipantResponse(float code, Participant participant, ArrayList<Karateka> karateka, String msg) {
this.code = code;
this.participant = participant;
this.karateka = karateka;
this.msg = msg;
}
public ParticipantResponse(float code, ArrayList<Participant> participants, String msg) {
this.code = code;
this.participants = participants;
this.msg = msg;
}
}
А это модель участника
public class Participant {
ArrayList<Participant> scoring = new ArrayList<Participant>();
public ArrayList<Participant> getScoring() {
return scoring;
}
public Participant (){
}
@SerializedName("name")
private String name;
@SerializedName("photo_profile")
private String photo_profile;
@SerializedName("id_user")
private float id_user;
@SerializedName("id_group")
private String id_group;
@SerializedName("admin_user_group")
private String admin_user_group;
@SerializedName("points")
private float points;
@SerializedName("own_budget")
private float own_budget;
@SerializedName("updated_at")
private String updated_at = null;
@SerializedName("created_at")
private String created_at;
@SerializedName("id")
private String id;
public Participant(float id_user, String id_group, String admin_user_group, float points, float own_budget, String updated_at, String created_at, String id) {
this.id_user = id_user;
this.id_group = id_group;
this.admin_user_group = admin_user_group;
this.points = points;
this.own_budget = own_budget;
this.updated_at = updated_at;
this.created_at = created_at;
this.id = id;
}
public void setId_user(float id_user) {
this.id_user = id_user;
}
public void setAdmin_user_group(String admin_user_group) {
this.admin_user_group = admin_user_group;
}
public void setPoints(float points) {
this.points = points;
}
public void setOwn_budget(float own_budget) {
this.own_budget = own_budget;
}
public void setUpdated_at(String updated_at) {
this.updated_at = updated_at;
}
public void setCreated_at(String created_at) {
this.created_at = created_at;
}
public void setId(String id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setPhoto_profile(String photo_profile) {
this.photo_profile = photo_profile;
}
public void setId_group(String id_group) {
this.id_group = id_group;
}
public float getId_user() {
return id_user;
}
public String getName() {
return name;
}
public String getPhoto_profile() {
return photo_profile;
}
public String getId_group() {
return id_group;
}
public String getAdmin_user_group() {
return admin_user_group;
}
public float getPoints() {
return points;
}
public float getOwn_budget() {
return own_budget;
}
public String getUpdated_at() {
return updated_at;
}
public String getCreated_at() {
return created_at;
}
public String getId() {
return id;
}
}
Это ответ в Почтальон:
{
"code": 200,
"participants": [
{
"id": 6,
"own_budget": -7992,
"points": 0,
"admin_user_group": 1,
"id_user": 1,
"id_group": 4,
"created_at": "2020-04-07 19:13:48",
"updated_at": "2020-04-12 14:26:46",
"email": "pedor@gmail.com",
"name": "pedro",
"photo_profile": null
},
{
"id": 7,
"own_budget": 10000,
"points": 0,
"admin_user_group": 0,
"id_user": 3,
"id_group": 4,
"created_at": "2020-04-07 19:14:18",
"updated_at": "2020-04-07 19:14:18",
"email": "javier@gmail.com",
"name": "javier",
"photo_profile": null
},
{
"id": 11,
"own_budget": 10000,
"points": 0,
"admin_user_group": 0,
"id_user": 5,
"id_group": 4,
"created_at": "2020-04-13 09:02:44",
"updated_at": "2020-04-13 09:02:44",
"email": "ernesto@gmail.com",
"name": "ernesto",
"photo_profile": null
},
{
"id": 20,
"own_budget": 10000,
"points": 0,
"admin_user_group": 0,
"id_user": 4,
"id_group": 4,
"created_at": "2020-04-13 09:49:40",
"updated_at": "2020-04-13 09:49:40",
"email": "pepe@gmail.com",
"name": "pepe",
"photo_profile": null
},
{
"id": 63,
"own_budget": 10000,
"points": 0,
"admin_user_group": 0,
"id_user": 2,
"id_group": 4,
"created_at": "2020-04-19 15:01:49",
"updated_at": "2020-04-19 15:01:49",
"email": "aitor@gmail.com",
"name": "aitor",
"photo_profile": null
},
{
"id": 68,
"own_budget": 10000,
"points": 0,
"admin_user_group": 0,
"id_user": 17,
"id_group": 4,
"created_at": "2020-04-21 15:03:46",
"updated_at": "2020-04-21 15:03:46",
"email": "hulk@gmail.com",
"name": "Hulk",
"photo_profile": null
}
],
"msg": "Get all participants by group"
}