Questions tagged [retrofit]

0

votes
1

answer
12

Views

How to store user ID of one person to other table in database?

I have 2 tables in database user_info and product_info.I save user_id,name,email,etc in user_info and product_id,product_name,product_description in product info.Now I have to look for a particular product so how do I get which product was uploaded by whom.How to link user_info with product_info in...
Parth Shah
1

votes
1

answer
192

Views

how can I pass header using @Part in retrofit?

My interface is like this @Multipart @NonNull @FormUrlEncoded @POST("upload") Call uploadImage(@Header("Authorization") MultipartBody.Part token, @Part("image") MultipartBody.Part image, @Part("kilometer") MultipartBody.Part distance); method for uploading image and data public void upload(final Str...
ben10
10

votes
3

answer
152

Views

How to use FCM notification with blogger using retrofit

I looking for the way to setup FCM Server Protocol if there's no hosting/own server Managed by google like blogger template's, and setup the dependencies on project. I see in this question. some answers contains code similar to retrofit codes using "okhttp3" String SCOPE = "https://www.googleapis.c...
Dr Mido
0

votes
0

answer
3

Views

java.net.SocketTimeoutException occurred after 1s~3s but my ok http timeout set 10s

My app is using Retrofit+okhttp. Sometimes, it throw SocketTimeoutException just through 1s~3s after request but my okhttp timeout is setting 10s. It's my code. private static OkHttpClient getClient() { OkHttpClient client = new OkHttpClient.Builder() .connectTimeout(10, TimeUnit.SECONDS) .writeTime...
AllenHuang
2

votes
1

answer
21

Views

Activity's TextView is null

I'm trying to make an app to check the weather using OpenWeatherMap, Kotlin, Retrofit and MVP with clean architecture. The app is very simple, has only one activity and the layout shows different data according to the location that the user selects. When initiating the activity, this initializes the...
Andrés Lauga
1

votes
2

answer
620

Views

validateEagerly() method in Retrofit 2.0 (beta 2)

What exactly does validateEagerly() (Retrofit 2.0 beta 2) method do? Where can I apply this method? JavaDoc says that When calling create on the resulting Retrofit instance, eagerly validate the configuration of all methods in the supplied interface. but this description is not so clear.
Andrey Arzhannikov
1

votes
2

answer
1.2k

Views

Parse JSON tag name and value to map using Retrofit

I need to parse such kind of JSON: { "commodities": { "39": "GOLD", "41": "SILVER", "42": "PLATINUM-APR16", "85": "SUGAR (11) ", "108": "WHEAT", "116": "OIL-MAR16 (WTI CRUDE)", "130": "CORN ", "158": "COFFEE ", "180": "ORANGE S.A.", "282": "GOLD/JPY", "304": "GOLD/EUR", "332": "GOLD/TRY", "468": "C...
AnZ
1

votes
1

answer
725

Views

How to create ResponseBody instance for mocking retrofit

How to create ResponseBody object for mocking the below service? public interface SBRestfulApi { @FormUrlEncoded @POST("authentication/google_login/") Call auth(@Field("id_token") String idToken); } Written the below class for mocking, but unable to create the MediaType as it constructor is private....
Vivek Kumar
1

votes
1

answer
311

Views

@SerializedName(“home”) is it invalid annotation in order to implement parcelable

I am using Retrofit and have many pojo class according to json. Since I am Using Gson parsing I need to use: @SerializedName("home") private List home = new ArrayList(); @SerializedName("away") private List Away= new ArrayList(); public List getHome() { return home; } Now I want to implement Parcela...
DevKRos
1

votes
1

answer
248

Views

Retrofit 2: API Call Requests and Responces increases 1 per click

I am Using Retrofit2 in application, using the ServiceGenerator class below. public class ServiceGenerator { public static final String API_BASE_URL = " http://my.base.url"; private static OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); private static Gson gson = new GsonBuilder() .set...
Adarsh
1

votes
2

answer
393

Views

No HTTP request is send from retrofit /Android/

I'm trying to send data to an API from my Android project using Retrofit. Everything seems to work without errors but no http request leaves the application. I can confirm this with Wireshark screening and API console log. Here is an example pseudo code of this parts of my application: // sample c...
nikitz
1

votes
2

answer
898

Views

How to upload empty file with Retrofit 2?

I successfully set up an uploading images to my REST API via retrofit with this code: File imageFile = ImagePicker.getFileFromResult(this, resultCode, data); RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), imageFile); MultipartBody.Part body = MultipartBody.Part....
1

votes
2

answer
849

Views

Handle Background Refresh token call in Retrofit parallel network calls

I am new to android programming and Retrofit , I am making a sample app where i have to make two parallel network calls using access token. The problem comes when access token is expired and return 401 status code , if I see 401 HTTP status code I have to make a call to refresh token with this acces...
Ajay Beniwal
1

votes
1

answer
373

Views

Retrofit + RxJava - Not emitting when Fragment is restored, if I used Disposable.dispose()

I have a Fragment A that uses Retrofit to calls an API in onCreateView. The result will be used to display a list of objects. Fragment A also has a button which navigates to Fragment B, by commiting a FragmentTransaction and replace itself. (Fragment A onDestroyView triggered) Everything works well,...
Sira Lam
1

votes
1

answer
203

Views

Retrofit OKHTTP Offline caching not working

I read dozens of tutorial and Stackoverflow answers to my problem but nothing is working for me! Also, most of them are old so probably OKHTTP changed somehow. All I want is to enable offline caching for Retrofit. I am using GET I tried using only offlineCacheInterceptor as an Interceptor, but I kep...
Mena
1

votes
1

answer
50

Views

Retrofit calling wrong url if url string contains “~” symbol causes 404 Error

I have created retrofit client and api interface but retrofit skipping some part in url and calling wrong url here is full url http://192.168.0.201/~amol/eflbudget/budgetmanagements/test url which retrofit calling http://192.168.0.201/budgetmanagements/test/ this causing 404 error //here is my re...
imran khan
0

votes
1

answer
32

Views

Get arraylist in JSON

My JSON looked like this {"status":true,"error_message":[],"locations":[{"id":"12","name":"office"},{"id":"13","name":"home"}]} I'm using coroutine and retrofit to communicate with web service. I would like to get office and home in locations arrayList, but I only able to get office. fun getLocation...
Hoo
0

votes
0

answer
13

Views

How to work with retrofit in Android when JSON data is dynamic?

I am making an app that displays daily stock data to the user. The problem is, I am using retrofit to make the API calls. With this type of JSON, I would need a POJO with every stock symbol. This obviously isn't possible. I want to be able to do something along the lines of - listOfStocks[1].getQuo...
deepanshpahwa
0

votes
0

answer
15

Views

Getting null pointer exception when using multipart form data with retrofit

I'm trying to upload a file to my database but while uploading. Into the on response my app is crashing with an null object reference exception. Here is my error log: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.pmsapp.pojo.Result.getMessage()' on a null obj...
Ruchit Patel
1

votes
3

answer
2.9k

Views

Retrofit | Handle “server not found exception”

When trying to access a RESTful api from an android app, you want to check two things: That the User's wifi is enabled (and there's a established connection) Your app can actually reach the server. (my server is on a local network) I've managed to check for the first one, but I have no idea how to c...
FRR
1

votes
2

answer
2.3k

Views

retrofit and orm library throw StackOverflow

I try to use 2 libraries: square/Retrofit - Rest client satyan/sugar - db orm retrofit use gson, so do class public class Book{ String name; public Book(String name) { this.name = name; } } ok, retrofit succesfully get data from server and put in our Book class. now i want save this data. for use or...
nail
1

votes
1

answer
220

Views

Using varargs and callback in retrofit

I wonder how i could possibly fix this. I want to use a vararg for the loadid and i want to add a callback. As you know varargs should be the last in the list aswel as the callback. See the code below: void getEvents(@Path("id") long id, @Query("number") int number, @Query("age") int age, BaseCallba...
K Roobroeck
1

votes
2

answer
4.8k

Views

Using Retrofit in nested JSON Object

I am playing with Retrofit. I have trouble when the json value is/are JSONObjects like the ratings key [{ "title": "True Blood", "year": 2008, "watchers": 36, "ratings": { "percentage": 82, "votes": 8377, "loved": 7629, "hated": 748 } } ] In jsonschema2pojo, it says I have to create ratings key int...
chip
1

votes
1

answer
3.3k

Views

How to pass a multidimensional hash as query parameters using retrofit by Square

I have a map of string id's and points, from which I need to generate a path similar to this: .../?assessment[id_1][points]=3&assessment[id_2][points]=5 I'm not exactly sure how i would do something like this in retrofit. I've tried manually generating a string and appending it to the end of a reque...
android_student
1

votes
1

answer
2.2k

Views

Android Issue with Retrofit and RxJava

I get a following error when I call subscribe on an Observable that was returned from retrofit api call. I think it might be a Proguard issue. After much googling, I didn't find any fixes. Versions used Retrofit used 1.6.1 RxJava used 0.16.1 Let me know if more information is needed. 09-06 18:38:16...
Laimiux
1

votes
1

answer
2.6k

Views

rx-java: Subscribe to Observable in onHandleIntent of IntentService

I faced following issue which didn't manage to fix: I have an IntentService which performs some job in onHandleIntent method. Beside of some common things in this method I have to make a request to the backend and send required information. As everyone knows, onHandleIntent method works in its own t...
Sergey Trukhachev
1

votes
1

answer
976

Views

Retrofit Exception During Execution

I am new in java development and try to learn Retrofit api i am getting exception can any one help me ? i have paste my code and output exception below kindly take a look of it Thank you , package com.company; import com.sun.deploy.util.SessionState; import retrofit.Callback; import retrofit.RestAd...
Qasim Khokhar
1

votes
1

answer
4.5k

Views

Populate an Array Adapter using Retrofit

I am fairly new to Android development and just discovered Retrofit today. I am hoping to build an Android app that consumes my site's API and it looks like Retrofit fits the bill nicely. I am trying to populate a ListView with data returned in the form of JSON from my API but cannot figure out exac...
NightMICU
1

votes
2

answer
3k

Views

Unit Testing Android app that relies on Robolectric / RxJava / RxAndroid

I am using the Robolectric 3.0 snapshot. I have a test: @Test public void my_test() throws Exception { when(testReferenceManager.getUserServiceMock().checkUsernameAvailability(anyString())).thenReturn(Observable.just(Arrays.asList(new User("[email protected]", "password")))); when(testReferenceManager....
powerj1984
1

votes
1

answer
1.4k

Views

In Retrofit, what is meant by “callbacks will happen on the same thread that executed the HTTP request”?

The Retrofit Documentation states the following: For desktop applications callbacks will happen on the same thread that executed the HTTP request. I've attempted to understand this by studying the Retrofit source (particularly RestAdapter.java) and looking at a number of other similar SO questions (...
Trevor
1

votes
1

answer
448

Views

Is it possible to manipulate retrofit url without method parameter?

Network call are made like this @GET("/api/video/{slug}/show") void getVideoData(@Path("slug") String slug,Callbackcb); Now I need to add wariable path before "/api" e.g: /en/api/video/{slug}/show Or /sp/video/{slug}/show That parameter is global wide, so without setting alteration all network call...
Yarh
1

votes
2

answer
215

Views

Parse JSON with GSON based on filed value (used with retrofit)

I have two JSON objects with similar fields. The only difference is that the first one always has field type: "type1" And second can have anything in 'type' field except 'type1'. I want them to be parsed into java objects with different classes (using classes FirstType.class and OtherType.class). Is...
TpoM6oH
1

votes
1

answer
694

Views

TypedFile Retrofit and rename file

Using Retrofit 1.9. TypedFile typedFile = new TypedFile("image/jpg", new File(filePath)); I want to rename the file uploaded to the server. how can I do it?
Caipivara
1

votes
1

answer
2.4k

Views

Delete with body is still not working with Retrofit

I have tried everything I can but it still doesn't work. I have already use okhttp 2.0 and okhttp-urlconnection 2.0 combined with retrofit 1.9. The Delete Body still doesn't work and I've already check all the issue posted before for this problem but I still can't find the answer. Is there something...
Paula Kristin
1

votes
1

answer
229

Views

Why does Gson expect the beginning array but gets an object instead?

I'm using this JSON which stores some articles with Retrofit, but I have an error: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 Here's my code: RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint("http://www.example.com/") .setLogLevel(RestAdapter.LogLevel.FULL) .build()...
Dandy Okami
1

votes
7

answer
3.8k

Views

Android Retrofit failure()

Hello I am trying to make an app that will get the lat long from web url http://akshay.site90.net/getLats.php?username=rakesh And result will be in the form {"lat":"30.1328064900","longitude":"77.2865304300"} I am doing this using Android Retrofit.. But When I am opening the app the failure() of re...
Akshay Sood
1

votes
1

answer
781

Views

java.lang.RuntimeException Caused by: retrofit.RetrofitError: com.squareup.okhttp.Request$Builder

I'm using RetroFit version 1.9.0 to make a PUT request to add an image to a location while also using an access cookie, but before the image transfer even begins proper, I get the error: 09-14 13:35:12.718 21896-22689/com.company.app E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #5 java.lang.Runti...
Larpus
1

votes
2

answer
1.8k

Views

Android Retrofit Error

I have made an application that will make a request with some parameters to Google API that will return JSON as a response.. The problem is that this request will be made every 2 seconds. So now here my logcat is showing some error and calling failure() everytime here is my logcat: 09-14 18:03:55.33...
Akshay Sood
1

votes
2

answer
1.2k

Views

How to parse JSON arrays with retrofit

So I have a retrofit interface: public interface RestUserInformation { @GET("/api/me") void getInfo(Callback callback); } A RestAdapter: RestAdapter userInformation = newRestAdapter.Builder() .setEndpoint(IP_ADDRESS) .setRequestInterceptor(requestInterceptor) .build(); Which make API calls and recei...
Chris
1

votes
1

answer
972

Views

Retrofit: sending POST request

This is declaration of my POST request: @POST("/api/geo/getLoc") public void getFriendsLocation(@Field("Id") int Id, @Field("Number") String Number, @Field("FriendNumber") String FriendNumber, Callback response); This is how i try to send and handle this request: String ENDPOINT = "http://52.88.**.*...
neustart47

View additional questions