简体   繁体   English

Android / Java罕见且看似不可能的异常导致力量接近

[英]Android / Java rare and seemingly impossible exception causing force close

I have an interesting problem being reported to me from an android application I have published. 我从我发布的Android应用程序向我报告了一个有趣的问题。 I have a two-dimensional array that I am iterating through using two for loops like so: 我有一个二维数组,我正在迭代使用两个for循环,如下所示:

for (int i = 0; i < arr.length; ++i)
{
    for (int j = 0; j < arr[i].length; ++j)
    {
        if (arr[i][j] != 0)
            // does stuff
    }
}

The problem is, somehow arr[i][j] != 0 is throwing an ArrayIndexOutOfBoundsException. 问题是,不知何故,arr [i] [j]!= 0正在抛出一个ArrayIndexOutOfBoundsException。 But very rarely. 但很少。 I have thousands of people use the app on a daily basis and get maybe twenty force close reports. 我有成千上万的人每天使用该应用程序,并获得可能二十次强制关闭报告。

Is this something I can't avoid, maybe a problem with the phones memory, etc. or is there something I can do that I haven't thought of yet? 这是我无法避免的事情,可能是手机内存的问题等,还是我能做的事情,我还没有想到呢? Thanks. 谢谢。

This exception is not impossible if you have one thread reading the arrays while a second thread is mutating them. 如果您有一个线程读取数组而第二个线程正在改变它们,则此异常并非不可能。 Specifically, if the mutating thread is changing the size of array slices; 具体来说,如果变异线程正在改变数组切片的大小; eg 例如

array[i] = new Whatever[array[i].length - 1];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM