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

error: cant Find the networkInfo method

Hi am Using Android Studio when i am in my isNetWorkAvailible() method it doesnt show the networkInfo Method as i type it it shows an error `

package app.aryan.intelligentweatherapp;

import android.app.AlertDialog; import android.app.DownloadManager; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.nfc.Tag; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem;

import com.squareup.okhttp.Call; import com.squareup.okhttp.Callback; import com.squareup.okhttp.OkHttpClient; import com.squareup.okhttp.Request; import com.squareup.okhttp.Response;

import java.io.IOException; import java.net.Authenticator;

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    String apiKey = "9128496ffcbe8e4df9709ba56e90dfd4";
    double latitide = 37.8267;
    double longtitude = -122.423;
    String foreCastUrl = "https://api.forecast.io/forecast/"
            + apiKey + "/," + latitide + "," + longtitude;
    if (isNetworkAvailable()) {

        OkHttpClient client = new OkHttpClient();
        Request mRequest = new Request.Builder().url(foreCastUrl).build();

        Call mCall = client.newCall(mRequest);
        mCall.enqueue(new Callback() {
            @Override
            public void onFailure(Request request, IOException e) {

            }

            @Override
            public void onResponse(Response response) throws IOException {
                try {
                    Log.v(TAG, response.body().string());
                    if (response.isSuccessful()) {

                    } else {
                        alertUserAboutError();

                    }
                } catch (IOException e) {
                    Log.e(TAG, "Exception Caught: ", e);
                }

            }
        });
    }
        Log.d(TAG, "Main UI is Running!");

    }

private boolean isNetworkAvailable() {
   ConnectivityManager manager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info =  manager.getActiveNetworkInfo();
    boolean isAvailable = false;

}

private void alertUserAboutError() {
alertDialogFragement dialog = new alertDialogFragement();
    dialog.show(getFragmentManager() ,"error_dialog");
}

} `