У меня есть приложение, которое работает нормально, когда я создаю приложение с помощью Android Studio.Но происходит сбой, когда я делаю неподписанный apk, а затем устанавливаю приложение оттуда.Он вылетает при нажатии кнопки «Войти», когда я вызываю API с помощью модернизации.Пожалуйста, веди меня.
ОШИБКА:
2019-03-16 09:16:07.185 19648-19648/com.od.phr.staging E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.od.phr.staging, PID: 19648
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equalsIgnoreCase(java.lang.String)' on a null object reference
at com.od.phr.retrofit.PHRResponse.isSuccess(Unknown Source:4)
at com.od.phr.retrofit.ApiCallback.onResponse(Unknown Source:474)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(Unknown Source:41)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:7000)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
Код активности:
public void signIn(JogetResponse.Listener<Boolean> listener, JogetResponse.ErrorListener errorListener, String userId, String pass) {
Pair<Boolean, List<String>> validate = mUser.validate(userId, pass, realm);
if (validate.first) {
User.UserPayload payload = new User.UserPayload(userId, pass, Constants.Action.LOGIN);
ApiManager.getInstance(getApplication().getApplicationContext()).loginUser(payload, new ApiCallback<PHRResponse<User>>() {
@Override
public void onSuccessCustomFunction(PHRResponse<User> response) {
}
@Override
public void onSuccess(PHRResponse<User> response) {
listener.onResponse(Boolean.TRUE);
}
@Override
public void onFail(Throwable throwable) {
errorListener.onErrorResponse(throwable);
}
});
} else {
errorListener.onErrorResponse(new Throwable(TextUtils.join("\n", validate.second)));
}
}
PHRResponse.java
public class PHRResponse<T> {
String status;
String msg;
T data;
public T getData() {
return data;
}
public boolean isSuccess() {
return status.equalsIgnoreCase("SUCCESS");
}
public String getErrorMessage() {
return msg;
}
}
ApiCallback.java
public abstract class ApiCallback<T> implements Callback<T> {
private String log = "";
public abstract void onSuccessCustomFunction(T response);
@Override
public final void onResponse(Call<T> call, Response<T> response) {
Log.i(Constants.TAG, "ApiCallback onResponse()");
log += "HTTP: [" + response.code() + "]\n" +
"HTTP Message: [" + response.message() + "]\n" +
"URL: [" + call.request().url().toString() + "]\n" +
"Method: [" + call.request().method() + "]\n" +
"Host: [" + call.request().url().host() + "]\n" +
"Query: [" + call.request().url().query() + "]\n";
Log.i(Constants.TAG, "ApiCallback onResponse() log: " + log);
switch (response.code()) {
case HttpsURLConnection.HTTP_OK:
case HttpsURLConnection.HTTP_CREATED:
case HttpsURLConnection.HTTP_ACCEPTED:
case HttpsURLConnection.HTTP_NOT_AUTHORITATIVE:
Log.i(Constants.TAG, "ApiCallback switch()");
if (response.body() != null) {
Log.i(Constants.TAG, "ApiCallback response.body() != null" +
": " + response.body());
Log.i(Constants.TAG, "ApiCallback response.raw() != null" +
": " + response.raw());
Log.i(Constants.TAG, "ApiCallback response.message() != null" +
": " + response.message());
Log.i(Constants.TAG, "ApiCallback response.toString() != null" +
": " + response.toString());
Log.i(Constants.TAG, "ApiCallback response.isSuccessful() : " +
": " + response.isSuccessful());
if (response.body() instanceof PHRResponse) {
Log.i(Constants.TAG, "response.body() instanceof PHRResponse");
PHRResponse phrResponse = (PHRResponse) response.body();
Log.i(Constants.TAG, "response.body() instanceof PHRResponse data : " + phrResponse.data);
Log.i(Constants.TAG, "response.body() instanceof PHRResponse msg : " + phrResponse.msg);
Log.i(Constants.TAG, "response.body() instanceof PHRResponse status : " + phrResponse.status);
Log.i(Constants.TAG, "response.body() instanceof PHRResponse getErrorMessage : " + phrResponse.getErrorMessage());
if (!phrResponse.isSuccess() ){
onFail(new Throwable(phrResponse.getErrorMessage()));
return;
}
}
Log.i(Constants.TAG, "ApiCallback switch 1(): " + response.body());
onSuccess(response.body());
onSuccessCustomFunction(response.body());
}
break;
case HttpsURLConnection.HTTP_FORBIDDEN:
Log.i(Constants.TAG, "HTTP_FORBIDDEN switch 1()");
case HttpsURLConnection.HTTP_UNAUTHORIZED:
Log.i(Constants.TAG, "HTTP_UNAUTHORIZED switch 1()");
doSessionTimeout();
// onUnauthorized ();перерыв;по умолчанию: Log.i (Constants.TAG, «переключатель по умолчанию 1 ()»);onFail (new Throwable (response.code () + "" + response.message ()));}}
@Override
public void onFailure(Call<T> call, Throwable t) {
Log.i(Constants.TAG, "onFailure switch 1()");
doError(t.getMessage());
}
public abstract void onSuccess(T response);
//public abstract void onSuccess(PHRResponse<User> response);
public abstract void onFail(Throwable throwable);
private void doError(String error) {
onFail(new Throwable(error));
}
}
Примечание. Работает нормально при установке из Android Studio, но вылетает, когда я делаю apk, а затем устанавливаю.