1
我的JSON:我得到零點異常的改造onResponse方法
{
"status": "1",
"login": "sucess"
}
這是我的模型類:
public class LoginModel {
@SerializedName("status")
@Expose
private String status;
@SerializedName("login")
@Expose
private String login;
...}
這是我的接口:
public interface RestInterface {
String url = "http://192.168.10.2/tourist/v1";
@FormUrlEncoded
@POST("/login")
Call<LoginModel> Login(@Field("email") String email,
@Field("pass") String passs);
}
這是我的來電方式:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(RestInterface.url)
.addConverterFactory(GsonConverterFactory.create())
.build();
//Creating Rest Services
final RestInterface restInterface = retrofit.create(RestInterface.class);
//Calling method to get check login
Call<LoginModel> response = restInterface.Login(Email.getText().toString(), Password.getText().toString());
response.enqueue(new Callback<LoginModel>() {
@Override
public void onResponse(Response<LoginModel> response, Retrofit retrofit) {
finish();
startActivity(getIntent());
Email.setText("");
Password.setText("");
LoginModel lm = response.body();
if (lm.getStatus().equals("1")) { //login Success
Toast.makeText(LoginActivity.this, "Login In SuccessFully", Toast.LENGTH_SHORT).show();
Intent i = new Intent(LoginActivity.this,AfterLoginActivity.class);
startActivity(i);
} else if (lm.getStatus().equals("0")) // login failure
{
Toast.makeText(LoginActivity.this, "Invalid UserName/Password ", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Throwable t) {
finish();
startActivity(getIntent());
// String merror = error.getMessage();
Toast.makeText(LoginActivity.this, "try again", Toast.LENGTH_LONG).show(); }
});
我在line => lm.getstatus()。中得到空點異常equals(1); 它改造之前工作正常1.9,然後我改變它爲改造2,現在得到零點異常!
異常日誌請。 – Amir
@Amir你能幫我用另一個代碼嗎?它正在改進GET請求方法,並直接進入onFailure();意思是沒有迴應 –