I am having problem with ActiveAndroid while saving data.
import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;
import com.google.gson.annotations.SerializedName;
@Table(name = "login_response")
public class LoginResponse extends Model{
@Column(name = "a_token")
@SerializedName("access_token")
public String mAccessToken;
@Column(name = "expiry_time")
@SerializedName("expires_in")
public Long mExpiresIn;
@Column(name = "refresh_token")
@SerializedName("refresh_token")
public String mRefreshToken;
@Column(name = "scope")
@SerializedName("scope")
public String mScope;
@Column(name = "token_type")
@SerializedName("token_type")
public String mTokenType;
public LoginResponse(){}
public String getAccessToken() {
return mAccessToken;
}
public void setAccessToken(String accessToken) {
mAccessToken = accessToken;
}
public Long getExpiresIn() {
return mExpiresIn;
}
public void setExpiresIn(Long expiresIn) {
mExpiresIn = expiresIn;
}
public String getRefreshToken() {
return mRefreshToken;
}
public void setRefreshToken(String refreshToken) {
mRefreshToken = refreshToken;
}
public String getScope() {
return mScope;
}
public void setScope(String scope) {
mScope = scope;
}
public String getTokenType() {
return mTokenType;
}
public void setTokenType(String tokenType) {
mTokenType = tokenType;
}
}
The above is the Mapping class for response obtained using retrofit while fetching data from web api. But I got and error like this.
FATAL EXCEPTION: main Process: com.bidhee.onlinepayment, PID: 3826 java.lang.IllegalArgumentException: Unable to create converter for class com.bidhee.onlinepayment.model.login.LoginResponse for method LoginApi.getResponse at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:695) at retrofit2.ServiceMethod$Builder.createResponseConverter(ServiceMethod.java:681) at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:166) at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:166) at retrofit2.Retrofit$1.invoke(Retrofit.java:145) at java.lang.reflect.Proxy.invoke(Proxy.java:393) at $Proxy2.getResponse(Unknown Source) at com.bidhee.onlinepayment.ui.viewpresenter.login.LoginPresenterImpl.attemptLogin(LoginPresenterImpl.java:39) at com.bidhee.onlinepayment.ui.viewpresenter.login.LoginRegisterActivity.onBtnSignInClicked(LoginRegisterActivity.java:93) at com.bidhee.onlinepayment.ui.viewpresenter.login.LoginRegisterActivity$$ViewBinder$1.doClick(LoginRegisterActivity$$ViewBinder.java:23) at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22) at android.view.View.performClick(View.java:5198) at android.view.View$PerformClick.run(View.java:21147) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.SecurityException: Can't make field constructor accessible at java.lang.reflect.Constructor.setAccessible(Constructor.java:334) at com.google.gson.internal.ConstructorConstructor.newDefaultConstructor(ConstructorConstructor.java:101) at com.google.gson.internal.ConstructorConstructor.get(ConstructorConstructor.java:83) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:95) at com.google.gson.Gson.getAdapter(Gson.java:416) at com.google.gson.internal.bind.MapTypeAdapterFactory.getKeyAdapter(MapTypeAdapterFactory.java:140) at com.google.gson.internal.bind.MapTypeAdapterFactory.create(MapTypeAdapterFactory.java:125) at com.google.gson.Gson.getAdapter(Gson.java:416) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldAdapter(ReflectiveTypeAdapterFactory.java:135) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.(ReflectiveTypeAdapterFactory.java:105) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:104) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:160) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:96) at com.google.gson.Gson.getAdapter(Gson.java:416) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldAdapter(ReflectiveTypeAdapterFactory.java:135) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.(ReflectiveTypeAdapterFactory.java:105) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:104) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:160) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:96) at com.google.gson.Gson.getAdapter(Gson.java:416) at retrofit2.converter.gson.GsonConverterFactory.responseBodyConverter(GsonConverterFactory.java:63) at retrofit2.Retrofit.nextResponseBodyConverter(Retrofit.java:325) at retrofit2.Retrofit.responseBodyConverter(Retrofit.java:308) at retrofit2.ServiceMethod$Builder.createResponseConverter(ServiceMethod.java:679) at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:166) at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:166) at retrofit2.Retrofit$1.invoke(Retrofit.java:145) at java.lang.reflect.Proxy.invoke(Proxy.java:393) at $Proxy2.getResponse(Unknown Source) at com.bidhee.onlinepayment.ui.viewpresenter.login.LoginPresenterImpl.attemptLogin(LoginPresenterImpl.java:39) at com.bidhee.onlinepayment.ui.viewpresenter.login.LoginRegisterActivity.onBtnSignInClicked(LoginRegisterActivity.java:93) at com.bidhee.onlinepayment.ui.viewpresenter.login.LoginRegisterActivity$$ViewBinder$1.doClick(LoginRegisterActivity$$ViewBinder.java:23) at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22) at android.view.View.performClick(View.java:5198) at android.view.View$PerformClick.run(View.java:21147) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
It was working fine before ActiveAndroid But when I am trying to use Active android I got the above errors. I can same the manually created object of different class and save it but while using retrofit and active android I can't.
I am using retrofit with the dependencies
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
This is how I am building the retrofit client
okhttpClientBuilder = new OkHttpClient.Builder();
retrofitBuilder = new Retrofit.Builder();
client = okhttpClientBuilder
.addInterceptor(new ApiInterceptor())
.build();
retrofit = retrofitBuilder
.baseUrl(BuildConfig.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();
The way I am calling the api is
Retrofit retrofit = OnlinePaymentApplication.getRetrofit();
APIs.LoginApi api = retrofit.create(APIs.LoginApi.class);
Call<LoginResponse> call = api.getResponse(grantType, clientId, clientSecret, userName, userPassword);
call.enqueue(new Callback<LoginResponse>() {
@Override
public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) {
loginView.hideProgress();
if (response.isSuccessful()) {
loginView.onLoginDataReceived(response.body());
} else {
ErrorResponse error = ErrorUtils.parseError(response);
loginView.onErrorMessageReceived(error.getMessage());
}
}
@Override
public void onFailure(Call<LoginResponse> call, Throwable t) {
loginView.hideProgress();
if (t instanceof IOException) {
loginView.onErrorMessageReceived(MetaData.NETWORK_ERROR);
} else {
loginView.onErrorMessageReceived(t.getLocalizedMessage());
}
}
});