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) Networking Building an HTTP Request

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

I am stuck in here, can someone please help me? Thanks!

@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_movie); OkHttpClient Client= new OkHttpClient(); Request request=new RequestBuilder().url(apiUrl).build();

MovieActivity.java
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MovieActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_movie);
        OkHttpClient Client= new OkHttpClient();
        Request request=new RequestBuilder().url(apiUrl).build();

        // Get some movie information!
        String apiUrl = "http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=xyz&q=hobbit";
    }
}

4 Answers

You're actually very close to the correct answer. There are just two things you need to change.

The line:

Request request=new RequestBuilder().url(apiUrl).build();

Should be

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

This is because Builder() is a static method of the Request class.

The second change is that you need to move that line so that it's below the line that defines "apiUrl". Where you have it now it won't know what that variable is. If you make those two changes you should be able to pass the test.

eeeee eeee
eeeee eeee
16,283 Points

I even copy pasted the line man it still doesn't work, don't get it

eeeee eeee
eeeee eeee
16,283 Points

Wow if anyone have problem with it even if you are pretty sure you did it correctly I tell you how it passed for me. As a parameter for the url() instead of apiUrl I copy pasted the url itself "http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=xyz&q=hobbit" (this is different for you, don't copy it from here)

and this is how it worked for me, interesting.

I cant figure it out where this line shld go........im stuck

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

Here is the questions: Next we need to create and build a Request. Declare a new Request variable, and then set it by chaining a few methods together. First use new Request.Builder(), then chain the url() method using apiUrl as the parameter. Then chain build() to finish.

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

Thanks Patrick, it worked :)