为什么demo不能用

来源:4-1 通用网络框架封装

qq_爱简单_4

2017-05-26 16:01

我下载了demo 调用  CommonOkHttpClient.post(CommonRequest.createPostRequest(url,params),handler);  怎么提示是    java.lang.ExceptionInInitializerError  这个错误的  。。不能用。

写回答 关注

2回答

  • 程忠华3788958
    2018-03-01 17:21:46

    请问在那里下载的   ,地址是多少?


  • JaydenJune
    2017-08-21 11:45:28

    你好.由于

    @Override
    public X509Certificate[] getAcceptedIssuers() {
       return null;
    }

    返回null导致

    因为OKhttpClient类中的sslSocketFactory()方法实现,有一个非空判断(看下面的代码第二行)

    public Builder sslSocketFactory(SSLSocketFactory sslSocketFactory) {
     if (sslSocketFactory == null) throw new NullPointerException("sslSocketFactory == null");
     X509TrustManager trustManager = Platform.get().trustManager(sslSocketFactory);
     if (trustManager == null) {
       throw new IllegalStateException("Unable to extract the trust manager on " + Platform.get()
           + ", sslSocketFactory is " + sslSocketFactory.getClass());
     }
     this.sslSocketFactory = sslSocketFactory;
     this.certificateChainCleaner = CertificateChainCleaner.get(trustManager);
     return this;
    }

    修改方法:


    在httputils类中添加

    private static final X509Certificate[] AcceptedIssuers = new X509Certificate[] {};

    @Override
    public X509Certificate[] getAcceptedIssuers() {
       return AcceptedIssuers ;
    }

    返回 AcceptedIssuers 问题解决

okhttp框架解析与应用

本课绝对让你掌握okhttp网络框架,了解源码及其执行流程

21187 学习 · 41 问题

查看课程

相似问题