user11664301
user11664301

Reputation:

Do you know anything about this retrofit error?

This is the message that show the console.

Process: com.example.claseandroid, PID: 8609
java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.runtime/javalib/core-oj.jar)
    at okhttp3.internal.Util.<clinit>(Util.java:87)
    at okhttp3.internal.Util.skipLeadingAsciiWhitespace(Util.java:321)
    at okhttp3.HttpUrl$Builder.parse(HttpUrl.java:1313)
    at okhttp3.HttpUrl.get(HttpUrl.java:917)
    at retrofit2.Retrofit$Builder.baseUrl(Retrofit.java:492)
    at com.example.claseandroid.ConectHeroku.getRetrofit(ConectHeroku.java:12)
    at com.example.claseandroid.ConectHeroku.getService(ConectHeroku.java:19)
    at com.example.claseandroid.MainActivity.getDataHeroku(MainActivity.java:26)
    at com.example.claseandroid.MainActivity.onCreate(MainActivity.java:21)
    at android.app.Activity.performCreate(Activity.java:7802)
    at android.app.Activity.performCreate(Activity.java:7791)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)

This is the Class that have error

public static final String herokuLink = "https://mongodev.herokuapp.com/api/";

private static Retrofit getRetrofit(){
    return new Retrofit.Builder()
            .baseUrl(herokuLink)
            .addConverterFactory(GsonConverterFactory.create())
            .build();
}

This method have interface class.

public static routerHeroku getService(){
    return getRetrofit().create(routerHeroku.class);
}

Upvotes: 3

Views: 3117

Answers (1)

Andriy Chopovenko
Andriy Chopovenko

Reputation: 141

This error caused by atempt to use java 8 features witout adding it to project, as since version 2.7.0 Retrofit require java 8. So try to add this to your module-level build.gradle

  android {
    compileOptions {
        targetCompatibility = "8"
        sourceCompatibility = "8"
    }
}

Upvotes: 13

Related Questions