当我使用Retrofit时,出现异常java.lang.NoClassDefFoundError:失败的解析度:Lokio / Buffer;我使用okhttpclient来设置Retrofit的标头。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);
Run Code Online (Sandbox Code Playgroud)
}
日志t.getMessage是:java.lang.NoClassDefFoundError:无法解决以下问题:Lokio / Buffer;
小智 5
我通过添加解决了它:
implementation 'com.squareup.okio:okio:2.1.0'
Run Code Online (Sandbox Code Playgroud)
在build.gradle(Module:app)下的依赖项中。
好吧~我上次也发现这个错误了。
通过这样:
NoClassDefFoundError: Failed resolution of: Lokio/Buffer
您可能会丢失另一个 jar lib-- Okio。
您可以从 github 下载 jar 文件:https:
//github.com/square/okio
并将此库添加到您的项目中。
| 归档时间: |
|
| 查看次数: |
4595 次 |
| 最近记录: |