ArrayIndexOutOfBoundsException - 改进调用

Sub*_*bby 16 android retrofit2

我试图PUT在我的Retrofit实例上调用一个方法:

Response<UpdateUserProfileResponse> response = App.getService().updateUserProfile(//A good 26 parameters).execute();
Run Code Online (Sandbox Code Playgroud)

其中的参数updateUserProfile()是String,Boolean和one的混合List<MyObject>.当我调用此方法时,我收到以下错误:

Throwing new exception 'length=238; index=1366' with unexpected pending exception: java.lang.ArrayIndexOutOfBoundsException: length=238; index=1366
06-28 21:53:12.458 3928-6610/com.subby.development A/art: art/runtime/thread.cc:1329]   at retrofit2.Response
Run Code Online (Sandbox Code Playgroud)

更新

我发现了这个问题.有两个RealmList<BackgroundString>导致问题.当我评估两个RealmLists时,我得到:

Unable to evaluate the expression method threw 'java.lang.IllegalStateException' exception.

qix*_*qix 33

对于任何绊倒这个问题的人来说,实际问题很可能是这样的:https://issuetracker.google.com/issues/37078190 即在Marshmallow上的Instant Run/23(甚至可能是24)在android运行时中存在问题.Android 8/26 +有官方修复,但对于大多数人来说,禁用Instant Run应该足够了.

还重新:
https://github.com/square/retrofit/issues/1486
https://github.com/square/retrofit/issues/1506


Abr*_*hew 17

投掷新的例外'长度= 1120; index = 2310',带有意外的挂起异常:java.lang.ArrayIndexOutOfBoundsException:length = 1120; 指数= 2310

它在Android Nougat和Oreo中运行良好,但我在Marshmallow遇到了这个问题.我只是通过关闭"即时运行"来修复它.通过转到文件 - >设置 - >构建,执行,部署 - >即时运行并禁用即时运行选项来执行此操作


小智 10

我也面临着同样的问题:

禁用Instant Run可解决问题。

请遵循以下路径:

设置->构建,执行,开发-> Instant Run


小智 0

将您的代码包装到 try catch 块中,就像我所做的那样

 Call<JsonObject> call = null;
        try
        {
            call = apiService.getUserList(getUsersListRequestModel);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
Run Code Online (Sandbox Code Playgroud)

  • 在“try-catch”块内替换代码不被认为是一个好的做法。 (2认同)