当我使用改造时。我得到了异常 java.lang.NoClassDefFoundError: Failed resolution of: Lokio/Buffer;我使用 okhttpclient 来设置改造的 header 。get userList 是一个 post 方法,我需要在请求中发送正文。

private void getUserList(int startIndex){
    final JSONObject audienceObj = ProtocolHelper.getProtocolUtils(mContext).getUserlistJsonObj(mRoomData.mUid, mRoomData.mRoomId, startIndex);
    OkHttpClient okClient = new OkHttpClient.Builder()
    .addInterceptor(
        new Interceptor() {
          @Override
          public okhttp3.Response intercept(Interceptor.Chain chain) throws IOException {
                Request original = chain.request();

                // Request customization: add request headers
                Request.Builder requestBuilder = original.newBuilder()
                        .header("sessionId", CommonData.getUserInfo(mContext).sessionId);
                Request request = requestBuilder.build();
                return chain.proceed(request);
            }
        })
    .build();


    String baseUrl = ProtocolUtils.BASE_URL+"/";
    Retrofit retrofit = new Retrofit.Builder()
    .baseUrl(baseUrl)
    .addConverterFactory(GsonConverterFactory.create())
    .client(okClient)
    .build();

    String audienceUrl = ProtocolHelper.getProtocolUtils(mContext).getProtocolUrl(ProtocolUtils.PROTOCOL_MSG_ID_MEMBER_LIST);
    AudienceInterface audienceInterface = retrofit.create(AudienceInterface.class);
    Call<String> call = audienceInterface.getAudienceList(audienceUrl,audienceObj);
    call.enqueue(new Callback<String>() {
        @Override
        public void onResponse(Call<String> call, Response<String> response) {
            Log.d(TAG, "onResponse");
        }

        @Override
        public void onFailure(Call<String> call, Throwable t) {
            Log.d(TAG, "onFailure"+t.getMessage());
        }
    });
}

public interface AudienceInterface {

@POST("{url}")
Call<String>getAudienceList(@Path("url") String url,@Body JSONObject boder);

}

日志 t.getMessage 是 :java.lang.NoClassDefFoundError: Failed resolution of: Lokio/Buffer;

最佳答案

好吧~我上次也发现这个错误。
这样:
NoClassDefFoundError:解析失败:Lokio/Buffer
您可能会丢失另一个 jar 库—— Okio
你可以从github下载jar文件:
https://github.com/square/okio
并将这个库添加到您的项目中。

关于retrofit - java.lang.NoClassDefFoundError : Failed resolution of: Lokio/Buffer;,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36995096/

10-13 03:42