简体   繁体   中英

Android studio error: element value constant expression

i am trying to set a value of @GET if i put direct value my API call work fine but if i trying to get that value from other class it giving me error element value must be a constant expression

API http://49.12.80.197/Vokka/getclientbalance.do?pin=923338875585

if i write @GET("getclientbalance.do") API Call works fine

any solution for it >?

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;


public class ApiClient {


    public static String BASE_URL = "http://49.12.80.197/Vokka/";
    public static String balance = "getclientbalance.do";
   

ApiInterface

import com.google.gson.JsonElement;

import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Query;
import retrofit2.http.Url;

import static com.kkdialer.voip.ApiClient.balance;

public interface ApiInterface {

    @GET(value = balance)
    Call<JsonElement> getclientbalance(@Query("pin") String mobileNo);

}

error: element value must be a constant expression @GET(value = balance)

What you're trying to achieve is a dynamic path for a request.

To cater that, @Path annotation has been provided by Retrofit, you can read more about it here .

Use it as:

@GET("{path}")
Call<JsonElement> getclientbalance(
    @Query("pin") String mobileNo,
    @Path("path") String yourPath
);

The purpose of @Path is to provide dynamic request URLs. For example, a separate request URL based on user's username.

It, also, has the functionality to encode or not encode the URLs, read the link provided above to know more.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM