Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Weather App (2015) Concurrency and Error Handling Making Our Code Asynchronous

M.Sneha Priyaa
M.Sneha Priyaa
1,042 Points

Request(com.squareup.Okhttp.request.builder)has private access in com.squareup.Okhttp.request.builder

when making request in OkHttpClient, Request is shown as an error and when i hover over it, i get above message.I am using android studio 1.2.1.1 . Is OkHttpClient compatible with it? and what does the above message mean and how can be resolved?

4 Answers

Hi again,

Looks like the problem is with that Request request line;

Your code is:

Request request = new Request().Builder.url(api).build();

It should read:

Request request = new Request.Builder().url(api).build();
M.Sneha Priyaa
M.Sneha Priyaa
1,042 Points

I made the change , but still i get same error!

Ah, the Request doesn't get parentheses, as it's a class reference for the Builder method; so you'd actually have to move the parentheses, not just add new ones. I've re-written it without those unneeded parentheses, and in the same manner the video shows.

Request request = new Request.Builder()
                .url(api)
                .build();

That should resolve the error message!

Hi M.Sneha,

Did you make your Request request = new Request.Builder().url(forecastUrl).build(); a private request?

Without posting your code, it's difficult to tell you what specifically is wrong. However, you can also download the project file used by the instructor and compare his code against yours.

M.Sneha Priyaa
M.Sneha Priyaa
1,042 Points

Thanks for the reply! No, i didn't make it private! Anyway here is my piece of code where the error persists:

public class MainActivity extends Activity { public static final String TAG = "Mainactivity";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    String apiKey = "ee227d1c896052a398e4b9bdbb82d02b";
    double latitude = 37.8267;
    double longitude = -122.423;
    String api = "https://api.forecast.io/forecast/" + apiKey + "/" + latitude + "," + longitude;
    OkHttpClient client = new OkHttpClient();
    Request request = new Request().Builder.url(api).build();
    Call call = client.newCall(request);
    call.enqueue(new Callback() {
        @Override
        public void onFailure(Request request, IOException e) {

            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this)
            .setTitle("oops!");
        }

        @Override
        public void onResponse(Response response) throws IOException {
            try{
                if (response.isSuccessful())
                    Log.v(TAG,response.body().string());
            }
            catch(IOException e){
                Log.e(TAG,"............caught exception",e);}

        }
    });

}

}

M.Sneha Priyaa
M.Sneha Priyaa
1,042 Points

Cool!Thanks ,error's gone!