Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrofit is unable to create call adapter

This is my UserService Interface

 @GET(Constants.Api.URL_LOGIN)
    String loginUser(@Field("email") String email, @Field("password") String pass, @Field("secret") String secret, @Field("device_id") String deviceid, @Field("pub_key") String pubkey, @Field("device_name") String devicename);

In the activity I am calling

retrofit = new Retrofit.Builder()
                .baseUrl(Constants.Api.URL_BASE)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
service = retrofit.create(UserService.class);
String status = service.loginUser(loginedt.getText().toString(), passwordedt.getText().toString(), secret, device_id, pub_key, device_name);

This creates an exception

java.lang.IllegalArgumentException: Unable to create call adapter for class java.lang.String
    for method UserService.loginUser

What am I doing wrong?

Gradle :

compile 'com.squareup.retrofit:retrofit:2.+'
compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta1'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta1'
like image 365
androidAnonDev Avatar asked Sep 05 '15 10:09

androidAnonDev


1 Answers

Since you have included addCallAdapterFactory(RxJavaCallAdapterFactory.create()), you are looking to use Observable's to manage your calls. In your interface, explicitly give the parameterized Observable instead of a Call --

@GET(Constants.Api.URL_LOGIN)
    Observable<String> loginUser(@Field("email") String email, @Field("password") String pass, @Field("secret") String secret, @Field("device_id") String deviceid, @Field("pub_key") String pubkey, @Field("device_name") String devicename);

and then your service methods create observables for you that you can subscribe to or use as the start of an observable pipeline.

Observable<String> status = service.loginUser(loginedt.getText().toString(), passwordedt.getText().toString(), secret, device_id, pub_key, device_name);
status.subscribe(/* onNext, onError, onComplete handlers */);
like image 156
iagreen Avatar answered Oct 06 '22 00:10

iagreen