Android Retrofit 2 - GET - error: element value must be a constant expression

Android Retrofit 2 - GET - error: element value must be a constant expression

Hi,

I have set GET for Retrofit2 in my android application as follows:


@GET(Constants.API_URL + Constants.TYPE)
Call> getApiDatas(@Header("X-AUTH-TOKEN") String token);
.......
Call> call = APIService.getApiDatas(Constants.TOKEN_KEY);
.......


And it works. However, I need to get a dynamic URL into the GET.

If instead of static final variables (public static final String)
@GET(Constants.API_URL + Constants.TYPE)

I will use a non-static variable here via the class Variables:
@GET(Constants.API_URL + Constants.TYPE)

So I get an error:

error: element value must be a constant expression

@GET(Constants.API_URL + Variables.getType())


Can anyone advise me how to get a dynamic URL variable into the GET URL for Retrofit2 in Android Studio?

Thanks

REPLY


Hi,

if in Android Studio you need to get a non-static variable for a dynamic URL for an Android application using Retrofit2 in GET, then do it like this, it works!


@GET
Call> getApiDatas(@Header("X-AUTH-TOKEN") String token, @Url String url);
.......
Call> call = APIService.getApiDatas(Constants.TOKEN_KEY, Constants.TYPE + Variables.getType());
.......

Související obsah

android

linux

ubuntu

programovani

android-studio

java

Komentáře

Vaše reakce na Android Retrofit 2 - GET - error: element value must be a constant expression

Reference

Podívejte se na naše reference

Prohlédnout

Aplikace

Podívejte se na naše aplikace

Prohlédnout

Co umíme?

Podívejte se co umíme

Prohlédnout

Co umíme?

Vytváříme sofistikované aplikace pro náročné

Od webových aplikací přes android až po převodové můstky či složité informační systémy.

Podívejte se k nám

Máte ještě čas? Podívejte se na další rubriky

Tento web používá soubory cookie. Dalším procházením tohoto webu vyjadřujete souhlas s jejich používáním.. Více informací zde.