Faced a problem when working with SurfaceView and drawing elements from an array, which is updated in another thread. The values in the array are always not null. Below I give the code and error messages. With what it can be connected? I will be very glad to help!
SurfaceViewThread:
@Override
        public void run() {
            Canvas canvas;
            while (runFlag) {
                canvas = null;
                try {
                    // получаем объект Canvas и выполняем отрисовку
                    canvas = surfaceHolder.lockCanvas(null);
                    synchronized (bw.multithreadLayers) {
                        if (canvas == null) return;
                        p.setShader(new LinearGradient(0, 0, 0, scrH, bw.getColor(), bw.getColor2(), Shader.TileMode.MIRROR));
                        canvas.drawPaint(p);
                        p.setShader(null);
                        p.setTextSize(textSize);
                        p.setColor(0xFFffffff);
                        for (int i = 0; i<bw.multithreadLayers.size(); i++) {
                            try {
                                for (int j = 0; j<bw.multithreadLayers.get(i).size(); j++) {
                                    GObject go = bw.multithreadLayers.get(i).get(j);
                                    canvas.drawBitmap(go.getTexture(), go.getX(), scrH-go.getY()-go.getTexture().getHeight(), p);
                                }
                            } catch(Exception e) {
                                System.out.println("JException, " + i + ", " + e.getMessage());
                            }
                        }
                        canvas.drawBitmap(player, objX, objY, p);
//some code...
                    }
                } 
                finally {
                    if (canvas != null) {
                        surfaceHolder.unlockCanvasAndPost(canvas);
                    }
                }
            }
        }
MultithreadLayers:
lowLayers.clear();
        lowLayers.add(layer0);
        lowLayers.add(layer1);
        lowLayers.add(layer2Active);
        multithreadLayers = lowLayers;
Exceptions:
06-19 08:05:41.967 I/System.out(30470): JException, 0, Attempt to invoke virtual method 'java.lang.Object java.util.ArrayList.get(int)' on a null object reference
And
06-19 08:05:43.601 I/System.out(30470): JException, 1, Index: 1, Size: 3
