Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当我尝试访问多维数组时,应用程序崩溃_Java_Android_Arrays - Fatal编程技术网

Java 当我尝试访问多维数组时,应用程序崩溃

Java 当我尝试访问多维数组时,应用程序崩溃,java,android,arrays,Java,Android,Arrays,出于某种神秘的原因,以下代码使我的Android应用程序崩溃: public class NearestFixMarker { private static MyArrayListMarker nearestFixMarker[] = new MyArrayListMarker[Configuration.Display.getNumberOfFixType()]; private static Bitmap icon[][] = new Bitmap[Configuration.Displ

出于某种神秘的原因,以下代码使我的Android应用程序崩溃:

public class NearestFixMarker {

private static MyArrayListMarker nearestFixMarker[] = new MyArrayListMarker[Configuration.Display.getNumberOfFixType()];

private static Bitmap icon[][] = new Bitmap[Configuration.Display.getNumberOfFixType()][GenericNdData.getNearestFixList().getNearestFixCount()];

public static void add(int color) {
    for (int i = 0; i < icon.length; i++) {
        Drawable d = DrawableUtils.resizeImageToDrawable(
                MapViewFragment.mapViewActivity,
                Configuration.Display.getDrawableFix(i),
                Configuration.MapView.getWaypointIconWidth(),
                Configuration.MapView.getWaypointIconHeight());
        d.setColorFilter(color, Mode.MULTIPLY);

        Bitmap b = ((BitmapDrawable) d).getBitmap();

        Paint pnt = new Paint();
        Canvas myCanvas = new Canvas(b);

        int myColor = b.getPixel(0,0);

        ColorFilter filter = new LightingColorFilter(myColor, color);
        pnt.setColorFilter(filter);

        myCanvas.drawBitmap(b,0,0,pnt);

        icon[i][0] = b;
        nearestFixMarker[i] = new MyArrayListMarker();
    }
}
    ...
}

显然,访问阵列会带来问题,但我不明白为什么会这样。我以前有一个简单的数组,它工作得很好。现在,我用多维数组替换了它,它崩溃了。我是否遗漏了一些明显的内容?

您在这一行遇到了异常

icon[i][0] = b;
此数组的大小为0,因此您可以访问0元素

Caused by: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0

异常状态表示数组的长度为零,并且您正在尝试访问其第零个索引。请确保数组不是空的!!你能告诉我是哪一行出错的吗?NearestFixMarker.add(NearestFixMarker.java:73)就是它。结果表明,GenericNdData.getNearestFixList().getNearestFixCount()值是在程序中稍后计算的,因此在执行此代码时,该值为0。非常感谢。
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0