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 Making an HTTP GET Request with OkHttp

Getting the NoClassDefFoundError error!

Please help me to solve this issue, I tried many ways and it didn't work :(

Can you be a bit more specific? It's hard to guess at which point in the video you did something that generated the above error. It helps even more if you can paste in the code you were changing when you got the error!

package abdulrahman.com.stormy;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class MainActivity extends AppCompatActivity {

    public static final String TAG = MainActivity.class.getSimpleName();

    protected void onCreate(Bundle savedInstanceState) {
        String apiKey = "***";
        double latitude = 37;
        double longitude = -122;
        String forecastUrl = "https://api.forecast.io/forecast/"+apiKey+"/"+latitude+","+longitude;

        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()

        Call call = client.newCall(request);
        call.enqueue(new Callback() {
            public void onFailure(Call call, IOException e) {


            public void onResponse(Call call, Response response) throws IOException {
                try {
                    Log.v(TAG, response.body().string());
                    if (response.isSuccessful()) {
                    else {
                } catch (IOException e) {
                    Log.e(TAG, "Exception caught: ", e);

        Log.d(TAG, "Main UI code is runing!");

    private void alertUserAboutError() {

        AlertDialogFragment dialog = new AlertDialogFragment();
        dialog.show(getFragmentManager(), "error");


//and this is the class

public class AlertDialogFragment extends DialogFragment {

    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Context context = getActivity();
        AlertDialog.Builder builder = new AlertDialog.Builder(context)
        AlertDialog dialog = builder.create();
        return dialog;


notice that I'v change the variable values String apiKey = "***"; double latitude = 37; double longitude = -122; it's not real.

one friend told me that issue is in the library!

3 Answers

When I test your query string: https://api.forecast.io/forecast/***/32,-122 I get a 400 Bad Request. So it looks like your friend may be right.

String apiKey = "bd0b75bbdd785c256cd8494010199985";
double latitude = 37.8267;
double longitude = -122.423;
String forecastUrl = "https://api.forecast.io/forecast/"+apiKey+"/"+latitude+","+longitude;

I did, and it works. You can try it too. Just copy it and paste it into the address bar of any browser.

I know link is working, but AS is not