我正在尝试使用Retrofit库插入数据。数据已成功插入,我也收到API的响应,但我的错误是我没有在AdminActivity.class
之后获得意图活动(Toast
)。谁可以帮我这个事??
private void createUserResponse() {
ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);
CreateUserRequest createUserRequest = new CreateUserRequest(editTextUserId.getText().toString().trim(),
editTextPassword.getText().toString().trim(),
editTextUserName.getText().toString().trim(),
editTextProfileImage.getText().toString().trim(), editTextSchoolId.getText().toString().trim(),editTextRole.getText().toString().trim());
Call<CreateUserResponse> createUserResponseCall = apiInterface. createUserCall(createUserRequest);
createUserResponseCall.enqueue(new Callback<CreateUserResponse>() {
@Override
public void onResponse(Call<CreateUserResponse> call, Response<CreateUserResponse> response) {
Log.d("CreateUser" , "onResponse: " + response.body().getMessage());
String status = response.body().getStatus();
if (status.equals("sucess")){
String message = response.body().getMessage();
Toast.makeText(getActivity(),"User Created Successfully" + message,Toast.LENGTH_SHORT).show();
Intent i = new Intent(getActivity(), AdminActivity.class);
startActivity(i);
} else{
String message = response.body().getMessage();
Toast.makeText(getActivity(),"" + message, Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<CreateUserResponse> call, Throwable t) {
}
});
}
答案 0 :(得分:0)
您的if-else
条件中存在拼写错误,因此即使您获得成功回复,您的代码也不会执行if
语句。
修正以下拼写错误,然后重试:
if (status.equals("success")) // fixed typo on "sucess" word