I am trying to make a class the uses Retrofit to make some API calls.
public class RedditUtils {
private RestAdapter restAdapter;
private RedditApiService service;
private final String redditBaseUrl = "https://oauth.reddit.com";
public RedditUtils()
{
restAdapter = new RestAdapter().Builder().setEndpoint(redditBaseUrl).build();
service = restAdapter.create(RedditApiService.class);
}
public void fetchToken(String token)
{
service.getToken(token, new Callback<RedditAccessToken>() {
@Override
public void success(RedditAccessToken redditAccessToken, Response response) {
Log.d("RedditAccessToken", redditAccessToken.getAccessToken());
}
@Override
public void failure(RetrofitError error) {
Log.d("RedditAccessTokenFailed", error.toString());
}
});
}
}
When I set restAdapter equalt to new RestAdapter(), I get the error
RestAdapter(*long path name*) has private access in 'retrofit.RestAdapter'
I am not sure what would be causing this error and I haven't found anyone else with this issue. Any ideas on how to solve the error?
You aren't suppose to instantiate RestAdapter
, hence why it has a private constructor.
Builder
is a static internal class of the RestAdapter
class. You can instantiate it like so:
new RestAdapter.Builder()
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.