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) Concurrency and Error Handling Making Our Code Asynchronous

Error unfortunately Stormy has stopped working

I followed all the instructions in the videos however when I try to run the app it crashes and says unfortunately stormy has stooped working not sure what I did wrong. Here is my code

MainActivity

package kharlmccatty.com.stormy;

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;

public class MainActivity extends ActionBarActivity {

public static final String TAG = MainActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
    String apiKey = "219970594bd1ef4c15dd623ae9828e93";
    double latitude = 37.8267;
    double longitude = -122.423;
    String forecastUrl = "https://api.forecast.io/forecast/" + apiKey +
            "/" + latitude + "," + longitude;

    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(Request request, IOException e) {

        }

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

        }
    });

}

}

buildgradle

apply plugin: 'com.android.application'

android { compileSdkVersion 21 buildToolsVersion "20.0.0"

defaultConfig {
    applicationId "kharlmccatty.com.stormy"
    minSdkVersion 14
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:21.0.3' compile 'com.squareup.okhttp:okhttp:2.1.0' }

Have a look in the logs for pointers as to which bit of code is causing the problem.

(I remember in this course there were times when the app was deliberately broken and then fixed to explain some concepts, so watch out for those too.)

1 Answer

Make sure you have this in your manifests/AndroidManifest.xml file:

<uses-permission android:name="android.permission.INTERNET" />

Im in the section of the video where it is suppose to run and I do have that kline of code.In the log cat it gives me this error android.app.SuperNotCalledException: Activity {kharlmccatty.com.stormy/kharlmccatty.com.stormy.MainActivity} did not call through to super.onCreate()

Not sure what it means

I figured out the problem I forget my super.onCreate method in the onCreate method. I think I deleted it by accident. Thanks for your help though.

Glad you sorted it.