Я использую модифицированную версию 2.0 для подключения к серверу, я получаю вывод в Postman, но пока я запускаю этот API в android, я получаю эту ошибку «протокол = http / 1.0, код = 500, сообщение = внутренняя ошибка сервера»
Это мой код интерфейса: -
public interface SetEmployeeActivityInterface {
@Headers("Accept: application/json")
@POST("setEmployeeActivity.php")
@FormUrlEncoded
Call<SetEmployeeActivityDetails> SET_EMPLOYEE_ACTIVITY_DETAILS_CALL
(@Field("user_id") String user_id,
@Field("secure_key") String secure_key,
@Field("order_id") String order_id,
@Field("home_in_location") String home_in_location,
@Field("home_in_date_time") String home_in_date_time,
@Field("home_out_location") String home_out_location,
@Field("home_out_date_time") String home_out_date_time,
@Field("cust_in_location") String cust_in_location,
@Field("cust_in_date_time") String cust_in_date_time,
@Field("cust_out_location") String cust_out_location,
@Field("cust_out_date_time") String cust_out_date_time,
@Field("lunch_in_location") String lunch_in_location,
@Field("lunch_in_date_time") String lunch_in_date_time,
@Field("lunch_out_location") String lunch_out_location,
@Field("lunch_out_date_time") String lunch_out_date_time,
@Field("hotel") String hotel,
@Field("comment") String comment);
}
Это мой код деталей API: -
public class SetEmployeeActivityDetails {
//{"output":[{"success":"yes","message":"Status successfully updated !"}]}
@SerializedName("output")
public List<SetEmployeeActivityDetails.SetEmployeeActivityOutput> setEmployeeActivityOutputList = new ArrayList();
public class SetEmployeeActivityOutput {
//{"output":[{"success":"no","message":"Successfully Updated !"}]}
@SerializedName("success")
public String success;
@SerializedName("message")
public String message;
}
}
Это мой код активности: -
dbHelper.updateJobCompletedStatus(customer_id, order_id, "yes");
//Calling webservise for send engineer activity
ArrayList<Query> getEngineerActivityQueryArrayList = new ArrayList<>();
getEngineerActivityQueryArrayList = dbHelper.getDataFromTb_Report_Status_table_for_Validation(user_id, order_id);
if (null != getEngineerActivityQueryArrayList && !getEngineerActivityQueryArrayList.isEmpty()) {
//Calling api for assign work
setEmployeeActivityInterface = APIClient.getClient().create(SetEmployeeActivityInterface.class);
Call<SetEmployeeActivityDetails> call2 = setEmployeeActivityInterface.SET_EMPLOYEE_ACTIVITY_DETAILS_CALL
(user_id, secure_key,order_id,
getEngineerActivityQueryArrayList.get(0).getHome_in_location(),
getEngineerActivityQueryArrayList.get(0).getHome_in_date_time(),
getEngineerActivityQueryArrayList.get(0).getHome_out_location(),
getEngineerActivityQueryArrayList.get(0).getHome_out_date_time(),
getEngineerActivityQueryArrayList.get(0).getCust_in_location(),
getEngineerActivityQueryArrayList.get(0).getCust_in_date_time(),
getEngineerActivityQueryArrayList.get(0).getCust_out_location(),
getEngineerActivityQueryArrayList.get(0).getCust_out_date_time(),
getEngineerActivityQueryArrayList.get(0).getLunch_in_location(),
getEngineerActivityQueryArrayList.get(0).getLunch_in_date_time(),
getEngineerActivityQueryArrayList.get(0).getLunch_out_location(),
getEngineerActivityQueryArrayList.get(0).getLunch_out_date_time(),
getEngineerActivityQueryArrayList.get(0).getHotel()
, getEngineerActivityQueryArrayList.get(0).getShort_day_comment());
// Set up progress before call
final ProgressDialog progressDoalog;
progressDoalog = new ProgressDialog(getActivity());
//progressDoalog.setMax(100);
progressDoalog.setMessage("Loading please wait...");
progressDoalog.setTitle("Nimble");
//progressDoalog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDoalog.setCancelable(false);
// show it
progressDoalog.show();
call2.enqueue(new Callback<SetEmployeeActivityDetails>() {
@Override
public void onResponse(Call<SetEmployeeActivityDetails> call, Response<SetEmployeeActivityDetails> response) {
progressDoalog.dismiss();
SetEmployeeActivityDetails signatureDetails = response.body();
List<SetEmployeeActivityDetails.SetEmployeeActivityOutput> userdata = signatureDetails.setEmployeeActivityOutputList;
if (userdata != null) {
for (SetEmployeeActivityDetails.SetEmployeeActivityOutput userdatavalue : userdata) {
}
}
}
@Override
public void onFailure(Call<SetEmployeeActivityDetails> call, Throwable t) {
progressDoalog.dismiss();
Toast.makeText(getActivity(), "Please try again... ", Toast.LENGTH_SHORT).show();
call.cancel();
}
});
Эта ошибка отображается в logcat: -
java.lang.NullPointerException: Attempt to read from field 'java.util.List nimble.nimble.nimble.APIDetails.SetEmployeeActivityDetails.setEmployeeActivityOutputList' on a null object reference
Я проверяю setEmployeeActivityOutputList, этот список равен нулю, и ответ будет внутренней ошибкой сервера.
вы получаете проверку NPE до того, как значение доступа
setEmployeeActivityOutputListне станет нулевым.