retrofit

(Retrofit) Could not locate converter for class crashing app

老子叫甜甜 提交于 2019-12-18 03:50:15
问题 So Retrofit 2.0.0 was recently released and theres not really any updated examples on how to use it, but im trying to implement it for a basic API call. Im getting a java.lang.IllegalArgumentException: Unable to create converter for class` caused by Caused by: java.lang.IllegalArgumentException: Could not locate converter for class orbyt.app.dataclass. Tried: * retrofit.OkHttpBodyConverterFactory When trying to make the api call. 回答1: I was facing the same issue. I fixed it by adding :

How to send Arrays / Lists with Retrofit

一曲冷凌霜 提交于 2019-12-18 03:17:09
问题 I need to send a list / an array of Integer values with Retrofit to the server (via POST) I do it this way: @FormUrlEncoded @POST("/profile/searchProfile") Call<ResponseBody> postSearchProfile( @Field("age") List<Integer> age }; and send it like this: ArrayList<Integer> ages = new ArrayList<>(); ages.add(20); ages.add(30); ISearchProfilePost iSearchProfile = gsonServerAPIRetrofit.create(ISearchProfilePost.class); Call<ResponseBody> call = iSearchProfile.postSearchProfile( ages ); The problem

Pause and resume downloads using Retrofit

杀马特。学长 韩版系。学妹 提交于 2019-12-18 03:02:04
问题 I used this tutorial to implement downloading files in my app: https://www.learn2crack.com/2016/05/downloading-file-using-retrofit.html The problem is that if internet speed is slow or if network fluctuates even for a second, the download is stopped permanently. Is there some way the app can detect that internet isn't active (connected but actually net isn't working), then pauses the download and resume when internet is fine. Or some alternative so user doesn't get frustrated? 回答1: I also

No Retrofit annotation found. (parameter #1)

ぃ、小莉子 提交于 2019-12-18 01:22:29
问题 I want get RSS code from a URL with Retrofit and if I enter url staticly in the get annotation everything is OK but with dynamic url I get an error. My interface service : public interface AllNewsService { @GET("/fa/rss/{url}") void getRss( @Path("url") String nGroup , Callback<AllNewsRss> callback);} And calling getRss method : DataGetter dg = new DataGetter(); dg.get().getRss("allnews" ,new Callback<AllNewsRss>() { @Override public void success(AllNewsRss allNewsRss, Response response) {

Is there a way to reuse builder code for retrofit

蹲街弑〆低调 提交于 2019-12-17 21:53:54
问题 I am using Retrofit and in every task I have to do something like this: public class MyTask extends AsyncTask<String, String, String> { private void someMethod() { final RestAdapter restAdapter = new RestAdapter.Builder() .setServer("http://10.0.2.2:8080") .build(); final MyTaskService apiManager = restAdapter.create(MyTaskService.class); } // ... } What is a good way to make this code DRY? 回答1: first you declare your parent class with all common behavior public abstract class MyAbstractTask

Retrofit - throwing an exception java.lang.IllegalArgumentException: Only one encoding annotation is allowed

别来无恙 提交于 2019-12-17 20:12:09
问题 Hello guys here is my sample code @FormUrlEncoded @Multipart @POST("registration.php") Call<Signup> getSignupResponse(@Field("email") String email, @Field("lname") String lname, @Field("fname") String fname, @Field("password") String password, @Part("filename") File file); Issue is when i am trying to add File Parameter as a Part its throwing me a error other wise if i use only @Field it works great but not working after i add @Part in it - is there a no way to use @Field and @part together

Use retrofit to download image file

拟墨画扇 提交于 2019-12-17 19:23:22
问题 I use Retrofit 1.6.0 on my Android project, the request url: https://example.com/image/thumbs/filename/sample.png My interface like this: public interface ImageService { @GET("/image/thumbs/filename/{filename}") @Streaming void getThumbs( @Path("filename") String filename, Callback<Response> callback ); } HTTP request was success, but there some error occur D/Retrofit(27613): ---> HTTP GET https://example.com/image/thumbs/filename/sample.png D/Retrofit(27613): ---> END HTTP (no body) D

multiple api request using retrofit and rx java

雨燕双飞 提交于 2019-12-17 19:03:31
问题 I am new to android and I have a scenario where I want to get get data from multiple api. Let suppose api_a , api_b , api_c , api_d . These api are independent of each other but I want to show data from these api in a mix Recycler View ( horizontal and vertical ). So I want to make these api call in such a manner so that I can get every api data at a time so that i can display in recycler view. I already using retrofit 2 but for that I had to chain them one by one which is very lengthy and I

Retrofit 2 can't upload a file with two additional separate string parameters

岁酱吖の 提交于 2019-12-17 18:52:03
问题 Read edit at bottom of the question for possible alternative solution until the solution is found . This is a successful post file with two parameters using POSTMan. I am trying to do the same with retrofit but receive BadRequest. PostMan Settings: Chrome Network Post Details: Now here is how I am doing this in Android but failing: Retrofit Service Interface: @Multipart @POST("jobDocuments/upload") Call<ResponseBody> upload(@Part("file") MultipartBody.Part file,@Part("folder") MultipartBody

GSON ignore elements with wrong type

别等时光非礼了梦想. 提交于 2019-12-17 18:14:11
问题 I'm using Retrofit (in combination with OkHttp and GSON) to communicate with an online webservice. The webservice has a default wrapper around all it's responses, similar to: { "resultCode":"OK", "resultObj":"Can be a string or JSON object / array", "error":"", "message":"" } In this example resultCode will either be OK or NO . Furthermore error and message only have any contents when an error has occured while processing the request. And last, but not least, resultObj will contain the actual