Android APK crashes on run in release mode, but not in debug mode.
Error:
java.lang.NullPointerException :Form-encoded method must contain at least one @Field.
....
at android.os.Handler.handleCallback(Handler.java:742)
at android.os.Handler.dispatchMessage(Handler.java:95)
Apiinterface.java
@FormUrlEncoded
@POST("api/login")
Call
LoginActivity.java
private void login() {
if (commonUtils.isNetworkAvailable()) {
pd.show();
ApiInterface apiService =
ApiClient.getClient().create(ApiInterface.class);
call = apiService.login("" + inputEmail.getText().toString().trim(), "" + inputPassword.getText().toString().trim());
call.enqueue(new Callback<LoginModel>() {
@Override
public void onResponse(Call<LoginModel> call, Response<LoginModel> response) {
if (response.isSuccessful()) {
LoginModel model = response.body();
if (model.isSuccess()) {
sharedPref.setBoolean(sharedPref.LOGIN, true);
sharedPref.setDataInPref(sharedPref.USER_ID, model.getId());
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
} else {
CommonUtils.alertDialog(LoginActivity.this,model.getMessage(),"Error");
}
}
if (pd != null && pd.isShowing())
pd.dismiss();
}
@Override
public void onFailure(Call<LoginModel> call, Throwable t) {
// Log error here since request failed
if (pd != null && pd.isShowing())
pd.dismiss();
}
});
} else {
CommonUtils.alertDialog(LoginActivity.this,getString(R.string.internet_disconnect));
}
}
That indicates a problem with your APK, not the library. Usually this is due to things like ProGuard. Since it's a usage problem and not a bug or feature request for Retrofit, please ask on StackOverflow with the 'retrofit' tag.
I had the same issue:
Fatal Exception: java.lang.IllegalArgumentException: Form-encoded method must contain at least one @Field.
for method b.b
at retrofit2.ServiceMethod$Builder.methodError(Unknown Source)
at retrofit2.ServiceMethod$Builder.methodError(Unknown Source)
at retrofit2.ServiceMethod$Builder.build(Unknown Source)
at retrofit2.Retrofit.loadServiceMethod(Unknown Source)
at retrofit2.Retrofit$1.invoke(Unknown Source)
at $Proxy1.b(Unknown Source)
at com.wrx.quickeats.activities.SignUp.onClick(Unknown Source)
at android.view.View.performClick(View.java:4452)
at android.view.View$PerformClick.run(View.java:18451)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5421)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:979)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795)
at dalvik.system.NativeStart.main(NativeStart.java)
i set both minifyEnabled and shrinkResources to false on my build.gradle and it worked: _minifyEnabled false_
_shrinkResources false_
Most helpful comment
I had the same issue:
Fatal Exception: java.lang.IllegalArgumentException: Form-encoded method must contain at least one @Field.
for method b.b
at retrofit2.ServiceMethod$Builder.methodError(Unknown Source)
at retrofit2.ServiceMethod$Builder.methodError(Unknown Source)
at retrofit2.ServiceMethod$Builder.build(Unknown Source)
at retrofit2.Retrofit.loadServiceMethod(Unknown Source)
at retrofit2.Retrofit$1.invoke(Unknown Source)
at $Proxy1.b(Unknown Source)
at com.wrx.quickeats.activities.SignUp.onClick(Unknown Source)
at android.view.View.performClick(View.java:4452)
at android.view.View$PerformClick.run(View.java:18451)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5421)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:979)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795)
at dalvik.system.NativeStart.main(NativeStart.java)
i set both minifyEnabled and shrinkResources to false on my build.gradle and it worked: _minifyEnabled false_
_shrinkResources false_