java - ArrayIndexOutOfBoundsException - Retrofit 2.4.0 调用
问题描述
我正在尝试POST
使用retrofit
. 它在某些设备上运行良好,但在带有 OS 版本的Nexus 5上崩溃6.0.1
。
但现在我面临一个例外
art/runtime/thread.cc:1344] 抛出新异常 'length=1903; index=3147' 出现意外挂起异常:java.lang.ArrayIndexOutOfBoundsException: length=1903; 索引=3147
我知道有很多问题但是对我没有任何帮助。我根据给定的帖子尝试了所有内容,例如this,this和this等。有些人通过禁用Instant Run解决了这个问题。但这对我不起作用。
我正在使用这些依赖项进行改造:
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
这是我的项目级 gradle 文件:
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.google.gms:google-services:4.0.1'
这是我得到的 API 调用ArrayIndexOutOfBoundsException
APIClient.getAPIService().getEffects(Constants.apiKey).enqueue(//callback);
这是我声明调用的 API 接口:
@FormUrlEncoded
@POST("/getEffects")
Call<GetEffectResp> getEffects(@Field("apikey") String apikey);
如果有人解决了这个问题,请帮我弄清楚。
TIA
解决方案
我也面临同样的问题。在我的情况下,我使用JsonElement
而不是Pojo 类来解决它。
下面是回调。你可以试试...
APIClient.getAPIService().getEffectsInternal(Constants.apiKey).enqueue(new Callback<JsonElement>() {
@Override
public void onResponse(Call<JsonElement> call, Response<JsonElement> response) {
Log.e("",""+response.body());
}
@Override
public void onFailure(Call<JsonElement> call, Throwable t) {
}
});
我希望这个对你有用。
推荐阅读
- reactjs - 反应单元测试 - 酶内部错误:带有标签2的未知节点
- excel - 如果在工作表上使用自动填充,则调用宏
- c# - Outlook 自动完成电子邮件列表
- amazon-web-services - 如何在 lambda 函数中使用 pyhive?
- xamarin.android - aapt2 删除资源 * 不需要默认值
- ionic4 - Ionic 4中带有令牌的Http
- unity3d - 防止对角线运动
- graphql - URQL - GraphQL 如何获取响应标头
- google-cloud-platform - 谷歌云平台试用
- javascript - 在 VS 代码量角器中编写简单代码时出错:ERROR:browser_switcher_service.cc(238)] XXX Init()