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!
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

Andrew Jake Villegas
2,289 PointsRun Time Exception Error
Here guys I have been trying to figure out what is going on with my project. Can you look at this Run Time Exception Error?
04-22 00:01:16.520 1122-1122/com.example.andrewjakevillegas.stormy E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.andrewjakevillegas.stormy, PID: 1122 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.andrewjakevillegas.stormy/com.example.andrewjakevillegas.stormy.MainActivity}: java.lang.RuntimeException: Unable to bind views for com.example.andrewjakevillegas.stormy.MainActivity at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2790) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2855) at android.app.ActivityThread.access$900(ActivityThread.java:181) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:6117) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) Caused by: java.lang.RuntimeException: Unable to bind views for com.example.andrewjakevillegas.stormy.MainActivity at butterknife.ButterKnife.bind(ButterKnife.java:322) at butterknife.ButterKnife.bind(ButterKnife.java:237) at com.example.andrewjakevillegas.stormy.MainActivity.onCreate(MainActivity.java:47) at android.app.Activity.performCreate(Activity.java:6374) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2743) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2855) at android.app.ActivityThread.access$900(ActivityThread.java:181) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:6117) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) Caused by: java.lang.IllegalStateException: Required view 'timeLabel' with ID 2131230803 for field 'mTimeLabel' was not found. If this view is optional add '@Nullable' annotation. at butterknife.ButterKnife$Finder.findRequiredView(ButterKnife.java:140) at com.example.andrewjakevillegas.stormy.MainActivity$$ViewBinder.bind(MainActivity$$ViewBinder.java:11) at com.example.andrewjakevillegas.stormy.MainActivity$$ViewBinder.bind(MainActivity$$ViewBinder.java:8) at butterknife.ButterKnife.bind(ButterKnife.java:319) at butterknife.ButterKnife.bind(ButterKnife.java:237) at com.example.andrewjakevillegas.stormy.MainActivity.onCreate(MainActivity.java:47) at android.app.Activity.performCreate(Activity.java:6374) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2743) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2855) at android.app.ActivityThread.access$900(ActivityThread.java:181) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:6117) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 04-22 00:01:16.530 1122-1122/com.example.andrewjakevillegas.stormy I/Process﹕ Sending signal. PID: 1122 SIG: 9
Here is my MainActivity.java
package com.example.andrewjakevillegas.stormy;
import android.app.DownloadManager;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.Text;
import java.io.IOException;
import butterknife.Bind;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class MainActivity extends ActionBarActivity {
public static final String TAG = MainActivity.class.getSimpleName();
private CurrentWeather mCurrentWeather;
@Bind(R.id.timeLabel) TextView mTimeLabel;
@Bind(R.id.temperatureLabel) TextView mTemperatureLabel;
@Bind(R.id.humidityValue) TextView mHumidityValue;
@Bind(R.id.precipValue) TextView mPrecipValue;
@Bind(R.id.summaryLabel) TextView mSummaryLabel;
@Bind(R.id.iconImageView) TextView mIconImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
String apiKey = "6742d289456f597f5aca440dc97c2b3b";
double latitude = 37.8267;
double longitude = -122.423;
String forecastURL = "https://api.forecast.io/forecast/" + apiKey +
"/" + latitude + "," + longitude;
if (isNetworkAvailable()) {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(forecastURL)
.build();
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
try {
String jsonData = response.body().string();
Log.v(TAG, jsonData);
if (response.isSuccessful()) {
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, getString(R.string.network_unavailable_message),
Toast.LENGTH_LONG).show();
}
Log.d(TAG, "Main UI code is running!");
}
private void updateDisplay() {
mTemperatureLabel.setText(mCurrentWeather.getTemperature() +"");
}
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"));
return new CurrentWeather();
}
private boolean isNetworkAvailable() {
ConnectivityManager manager = (ConnectivityManager)
getSystemService(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();
Here is my activity_mail.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:id="@+id/RelativeLayout"
android:background="#fffc970b">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="100"
android:id="@+id/temperatureLabel"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textColor="@android:color/white"
android:textSize="150dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/degreeimageView"
android:layout_alignTop="@+id/temperatureLabel"
android:layout_toRightOf="@+id/temperatureLabel"
android:layout_toEndOf="@+id/temperatureLabel"
android:layout_marginTop="50dp"
android:src="@drawable/degree"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="At 5:00 PM it will be"
android:id="@+id/timeLabel"
android:layout_above="@+id/temperatureLabel"
android:layout_centerHorizontal="true"
android:textColor="#95ffffff"
android:textIsSelectable="true"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Alcatraz Island, CA"
android:id="@+id/locationLabel"
android:layout_above="@+id/timeLabel"
android:layout_centerHorizontal="true"
android:layout_marginBottom="60dp"
android:textColor="@android:color/white"
android:textSize="24sp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/iconImageView"
android:layout_alignBottom="@+id/locationLabel"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="@drawable/cloudy_night"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/temperatureLabel"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:weightSum="100"
android:id="@+id/linearLayout">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="50">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="HUMIDITY"
android:id="@+id/humidityLabel"
android:textColor="#95ffffff"
android:gravity="center_horizontal"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="0.88"
android:id="@+id/humidityValue"
android:textColor="@android:color/white"
android:textSize="24sp"
android:gravity="center_horizontal"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="50">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RAIN/SNOW?"
android:id="@+id/precipLabel"
android:textColor="#95ffffff"
android:gravity="center_horizontal"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="100"
android:id="@+id/precipValue"
android:textColor="@android:color/white"
android:textSize="24sp"
android:gravity="center_horizontal"/>
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stormy with a chance of meatballs"
android:id="@+id/summaryLabel"
android:layout_below="@+id/linearLayout"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:textColor="@android:color/white"
android:textSize="18dp"
android:gravity="center_horizontal"/>
</RelativeLayout>
My AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.andrewjakevillegas.stormy" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I am really lost. Been trying to understand what is going on.
3 Answers

Andrew Jake Villegas
2,289 PointsI found the answer Steve! After a few weeks of toiling.
My butterknife library is giving me the problem. Since Jake Wharton updated the version of butterknife to ver 8, you have to copy the whole compiler library to your build gradle. I was just copying the dependencies and adding it to my gradle dependencies. Which is giving me the problem.
buildscript { repositories { mavenCentral() } dependencies { classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' } }
apply plugin: 'com.neenbedankt.android-apt'
dependencies { compile 'com.jakewharton:butterknife:8.0.1' apt 'com.jakewharton:butterknife-compiler:8.0.1' }

Steve Hunter
57,711 PointsHi Andrew,
Your code is getting upset around line 47 of MainActivity.java
. This is something to do with Butter Knife.
In your layout, try removing the android:textIsSelectable=
"true
" line from the timeLabel
TextView. This is the element that is causing problems. If you look through the error log, you come to: Caused by: java.lang.IllegalStateException: Required view 'timeLabel' with ID 2131230803 for field 'mTimeLabel' was not found.
Now, I've no idea what that means, but comparing your code to mine in this region, and I don't have the textIsSelectable
property included. This may mean you can do with it - so, as a starting point, I'd remove that and see if that fixes the problem, or generates another error that is easier to fix!!
I hope that helps,
Steve.

Andrew Jake Villegas
2,289 PointsSteve,
I have removed android:textIsSelectable="true" from timeLabel. To no avail, it still not working.
However, it seems somewhere within the process of @Bind is not working. I have switched this section of my MainActivity from
@Bind(R.id.timeLabel) TextView mTimeLabel; @Bind(R.id.temperatureLabel) TextView mTemperatureLabel;
to
@Bind(R.id.temperatureLabel) TextView mTemperatureLabel; @Bind(R.id.timeLabel) TextView mTimeLabel;
Now the error message says
Caused by: java.lang.IllegalStateException: Required view 'temperatureLabel' with ID 2131230801 for field 'mTemperatureLabel' was not found. If this view is optional add '@Nullable' annotation.
I am thinking somewhere within my Layout there is a bug that is hiding.

Steve Hunter
57,711 PointsOK - so the first Bind
is throwing the error ... let me have a closer look to see if I can spot anything!
Steve.

Steve Hunter
57,711 PointsHi Andrew,
I can't spot anything obvious; it must be some tiny issue. Have a look at my code in GitHub here. I'm using Butterknife 6.1.0.
Let me know how you get on.
Steve.

Andrew Jake Villegas
2,289 PointsLet me check it out Steve. Thank you. Hopefully I can find out what is going on. I will probably rebuild the project if worse comes to worst.