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

Miles Torres
Miles Torres
2,316 Points

I can't Install these build tools!

I KEEP GETTING THIS ERROR: Loading SDK information... Refresh Sources: Fetched Add-ons List successfully Refresh Sources Ignoring unknown package filter 'build-tools-24.0.0_rc2'Warning: The package filter removed all packages. There is nothing to install. Please consider trying to update again without a package filter.

2 Answers

Seth Kroger
Seth Kroger
56,413 Points

There's no longer an rc2 ("Release Candidate 2", i.e., pre-release) version of the v24 build tools. Either you need to update your app's build.gradle file buildToolsVersion to use rc3, or preferably a stable release like 23.0.3

Miles Torres
Miles Torres
2,316 Points

Never mind I did it. But now every thing is coming up red. Here all all of the errors. They will be the ones with the the number 7 surrounding them:

''' package com.example.milespc.stormy;

import android.app.FragmentManager; import android.content.Context; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast;

import org.json.JSONException; import org.json.JSONObject;

import java.io.IOException;

public class MainActivity extends ActionBarActivity {

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

private CurrentWeather mCurrentWeather;

@InjectView(7R7.id.timeLabel) TextView mTimeLabel;
@InjectView(7R7.id.temperatureLabel) TextView mTemperatureLabel;
@InjectView(7R7.id.humidityValue) TextView mHumidityValue;
@InjectView(7R7.id.precipValue) TextView mPrecipValue;
@InjectView(7R7.id.summaryLabel) TextView mSummaryLabel;
@InjectView(7R7.id.iconImageView) ImageView mIconImageView;
@InjectView(7R7.id.refreshImageView) ImageView mRefreshImageView;
@InjectView(7R7.id.progressBar) ProgressBar mProgressBar;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    7setContentView7(7R7.layout.activity_main);
    7ButterKnife7.inject(this);

    mProgressBar.setVisibility(View.INVISIBLE);

    final double latitude = 37.8267;
    final double longitude = -122.423;

    mRefreshImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getForecast(latitude, longitude);
        }
    });

    getForecast(latitude, longitude);

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

private void getForecast(double latitude, double longitude) {
    String apiKey = "27974c4bc33201748eaf542a6769c3b7";
    String forecastUrl = "https://api.forecast.io/forecast/" + apiKey +
            "/" + latitude + "," + longitude;

    if (isNetworkAvailable()) {
        toggleRefresh();

        7OkHttpClient7 client = new 7OkHttpClient7();
        7Request7 request = new 7Request7.Builder()
                .url(forecastUrl)
                .build();

        7Call7 call = client.7newCall7(request);
        call.7enqueue7(new 7Callback7() {
            @Override
            public void onFailure(7Request7 request, IOException e) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        toggleRefresh();
                    }
                });
                alertUserAboutError();

            }

            @Override
            public void onResponse(7Response7 response) throws IOException {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        toggleRefresh();
                    }
                });
                try {
                    String jsonData = response.7body7().string();
                    Log.v(TAG, jsonData);
                    if (response.7isSuccessful7()) {
                        mCurrentWeather = getCurrentDetails(jsonData);
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {

                                updateDisplay();
                            }
                        });
                    } else {
                        alertUserAboutError();
                    }
                } catch (IOException e) {
                    Log.e(TAG, "Exception caught: ", e);
                } catch (JSONException e) {
                    Log.e(TAG, "Exception caught: ", e);
                }
            }
        });
    } else {
        Toast.makeText(this, 7getString7(7R7.string.network_unavailable_message),
                Toast.LENGTH_LONG).show();
    }
}

private void toggleRefresh() {
    if (mProgressBar.getVisibility() == View.INVISIBLE) {
        mProgressBar.setVisibility(View.VISIBLE);
        mRefreshImageView.setVisibility(View.INVISIBLE);
    }
    else {
        mProgressBar.setVisibility(View.INVISIBLE);
        mRefreshImageView.setVisibility(View.VISIBLE);
    }
}

private void runOnUiThread(Runnable runnable) {
}

private void updateDisplay() {
    mTemperatureLabel.setText(mCurrentWeather.getTemperature() + "");
    mTimeLabel.setText("At " + mCurrentWeather.getFormattedTime() + " it will be");
    mHumidityValue.setText(mCurrentWeather.getHumidity() + "");
    mPrecipValue.setText(mCurrentWeather.getPrecipChance() + "%");
    mSummaryLabel.setText(mCurrentWeather.getSummary());

    Drawable drawable = getResources().getDrawable(mCurrentWeather.getIconId());
    mIconImageView.setImageDrawable(drawable);
}

private Resources getResources() {
    return null;
}

private CurrentWeather getCurrentDetails(String jsonData) throws JSONException {
    JSONObject forecast = new JSONObject(jsonData);
    String timezone = forecast.getString("timezone");
    Log.i(TAG, "From JSON: " + timezone);

    JSONObject currently = forecast.getJSONObject("currently");

    CurrentWeather currentWeather = new CurrentWeather();
    currentWeather.setHumidity(currently.getDouble("humidity"));
    currentWeather.setTime(currently.getLong("time"));
    currentWeather.setIcon(currently.getString("icon"));
    currentWeather.setPrecipChance(currently.getDouble("precipProbability"));
    currentWeather.setSummary(currently.getString("summary"));
    currentWeather.setTemperature(currently.getDouble("temperature"));
    currentWeather.setTimeZone(timezone);

    Log.d(TAG, currentWeather.getFormattedTime());

    return currentWeather;
}


private boolean isNetworkAvailable() {
    ConnectivityManager manager = (ConnectivityManager)
            7getSystemService7(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = manager.getActiveNetworkInfo();
    boolean isAvailable = false;
    if (networkInfo != null && networkInfo.isConnected()) {
        isAvailable = true;
    }

    return isAvailable;
}

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

private FragmentManager getFragmentManager() {
    return null;
}

} '''

Miles Torres
Miles Torres
2,316 Points

If this helps an error that pops up in my messages is '''Error:A problem occurred configuring project ':app'.

Could not resolve all dependencies for configuration ':app:_debugCompile'. Could not find com.android.support:support-annotations:23.3.0. Required by: Stormy:app:unspecified > com.jakewharton:butterknife:8.0.1 Stormy:app:unspecified > com.jakewharton:butterknife:8.0.1 > com.jakewharton:butterknife-annotations:8.0.1'''

Miles Torres
Miles Torres
2,316 Points

Then in my CurrentWeather class: '''package com.example.milespc.stormy;

import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone;

public class CurrentWeather { private String mIcon; private long mTime; private double mTemperature; private double mHumidity; private double mPrecipChance; private String mSummary; private String mTimeZone;

public String getTimeZone() {
    return mTimeZone;
}

public void setTimeZone(String timeZone) {
    mTimeZone = timeZone;
}

public String getIcon() {
    return mIcon;
}

public void setIcon(String icon) {
    mIcon = icon;
}

public int getIconId() {
    // clear-day, clear-night, rain, snow, sleet, wind, fog, cloudy, partly-cloudy-day, or partly-cloudy-night.
    int iconId = 7R7.drawable.clear_day;

    if (mIcon.equals("clear-day")) {
        iconId = 7R7.drawable.clear_day;
    }
    else if (mIcon.equals("clear-night")) {
        iconId = 7R7.drawable.clear_night;
    }
    else if (mIcon.equals("rain")) {
        iconId = 7R7.drawable.rain;
    }
    else if (mIcon.equals("snow")) {
        iconId = 7R7.drawable.snow;
    }
    else if (mIcon.equals("sleet")) {
        iconId = 7R7.drawable.sleet;
    }
    else if (mIcon.equals("wind")) {
        iconId = 7R7.drawable.wind;
    }
    else if (mIcon.equals("fog")) {
        iconId = 7R7.drawable.fog;
    }
    else if (mIcon.equals("cloudy")) {
        iconId = 7R7.drawable.cloudy;
    }
    else if (mIcon.equals("partly-cloudy-day")) {
        iconId = 7R7.drawable.partly_cloudy;
    }
    else if (mIcon.equals("partly-cloudy-night")) {
        iconId = 7R7.drawable.cloudy_night;
    }

    return iconId;
}

public long getTime() {
    return mTime;
}

public String getFormattedTime() {
    SimpleDateFormat formatter = new SimpleDateFormat("h:mm a");
    formatter.setTimeZone(TimeZone.getTimeZone(getTimeZone()));
    Date dateTime = new Date(getTime() * 1000);
    String timeString = formatter.format(dateTime);

    return timeString;
}

public void setTime(long time) {
    mTime = time;
}

public int getTemperature() {
    return (int)Math.round(mTemperature);
}

public void setTemperature(double temperature) {
    mTemperature = temperature;
}

public double getHumidity() {
    return mHumidity;
}

public void setHumidity(double humidity) {
    mHumidity = humidity;
}

public int getPrecipChance() {
    double precipPercentage = mPrecipChance * 100;
    return (int)Math.round(precipPercentage);
}

public void setPrecipChance(double precipChance) {
    mPrecipChance = precipChance;
}

public String getSummary() {
    return mSummary;
}

public void setSummary(String summary) {
    mSummary = summary;
}

} '''

Miles Torres
Miles Torres
2,316 Points

Never mind I have found the answer through research.