记使用OkHttp遇到的问题

1、  java.lang.BootstrapMethodError,使用的是okhttp3

2019-02-13 11:37:03.244 23271-23271/com.example.****.myandroidproject E/AndroidRuntime: FATAL EXCEPTION: main

    Process: com.example.****.myandroidproject, PID: 23271

    java.lang.BootstrapMethodError: Exception from call site #1 bootstrap method

        at okhttp3.internal.Util.(Util.java:87)

        at okhttp3.internal.Util.immutableList(Util.java:234)

        at okhttp3.OkHttpClient.(OkHttpClient.java:127)

        at com.example.yangxiaochun.myandroidproject.activity.OkHttpDemoActivity.initNetWork(OkHttpDemoActivity.java:34)

        at com.example.yangxiaochun.myandroidproject.activity.OkHttpDemoActivity.onCreate(OkHttpDemoActivity.java:29)

        at android.app.Activity.performCreate(Activity.java:7009)

        at android.app.Activity.performCreate(Activity.java:7000)

        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)

        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)

        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)

        at android.app.ActivityThread.-wrap11(Unknown Source:0)

        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)

        at android.os.Handler.dispatchMessage(Handler.java:106)

        at android.os.Looper.loop(Looper.java:164)

        at android.app.ActivityThread.main(ActivityThread.java:6494)

        at java.lang.reflect.Method.invoke(Native Method)

        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)

        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

    Caused by: java.lang.NoClassDefFoundError: Invalid descriptor: ()Ljava/lang/Throwable;.

        at okhttp3.internal.Util.(Util.java:87) 

        at okhttp3.internal.Util.immutableList(Util.java:234) 

        at okhttp3.OkHttpClient.(OkHttpClient.java:127) 

        at com.example.yangxiaochun.myandroidproject.activity.OkHttpDemoActivity.initNetWork(OkHttpDemoActivity.java:34) 

        at com.example.yangxiaochun.myandroidproject.activity.OkHttpDemoActivity.onCreate(OkHttpDemoActivity.java:29) 

        at android.app.Activity.performCreate(Activity.java:7009) 

        at android.app.Activity.performCreate(Activity.java:7000) 

        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214) 

        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731) 

        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 

        at android.app.ActivityThread.-wrap11(Unknown Source:0) 

        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 

        at android.os.Handler.dispatchMessage(Handler.java:106) 

        at android.os.Looper.loop(Looper.java:164) 

        at android.app.ActivityThread.main(ActivityThread.java:6494) 

        at java.lang.reflect.Method.invoke(Native Method) 

        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 

        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 


解决方式:在build.gradle中添加以下代码Java8的新特性

compileOptions{

    sourceCompatibility JavaVersion.VERSION_1_8

targetCompatibility JavaVersion.VERSION_1_8

}

你可能感兴趣的:(记使用OkHttp遇到的问题)