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

Fatal Error creating OkHTTP3 object

I've pretty much finished this library, but I've gotten a fatal error from one of the beginning stages in this video. I've isolated it down to this little bit of introductory code.

import okhttp3.OkHttpClient;

public class MainActivity extends AppCompatActivity {

protected void onCreate(Bundle savedInstanceState) {

    String URL = "https://api.darksky.net/forecast/****(secret-key)*****/37.8267,-122.4233";

    OkHttpClient client = new OkHttpClient();

Whenever I create the OkHTTPClient object or a Request object or anything at all from the OkHTTP3 library it crashes the program. The debugger says: "A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x68 in tid 18904 (xample.weather2), pid 18904 (xample.weather2)"

Then it states: "Cause: null pointer dereference" and proceeds to list off a ton of errors from memory and backtraces tons more errors from stuff in a directory called /system/libart64.

I'd really appreciate any help on this, because I've been scouring StackOverFlow and Google for days and can't find much help. Oh and yes, I've added the " implementation 'com.squareup.okhttp3:okhttp:3.14.1" to the gradle(Module:app), I've added the user-permission to the internet, and I've updated the minSDKversion and synced the new gradle build.

Thanks in advance!

2 Answers

Hi. Make sure you're using Java 8 with this version of the OkHttp library.

If you aren't, just add

android {
 // (...)
 compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8

in your build.gradle(Module: app) file.

Hope that helps :)

Omg it worked. Thank you so much. I don't think I would've ever figured that out.

You're welcome. I'm glad it worked :)