Android Build a Weather App Networking Making an HTTP GET Request with OkHttp

Max Green
Max Green
8,015 Points

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 = "****(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 :)

Max Green
Max Green
8,015 Points

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 :)