Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen onResume is called app throws ArrayIndexOutOfBouds
    primarykey
    data
    text
    <p>When I click home button onPause method is called but when I call application in front onResume is called and than it crashes. </p> <p>There is code when index is out of bouds: </p> <pre><code>while (isRunning) { if (!ourHolder.getSurface().isValid()) continue; Canvas canvas = ourHolder.lockCanvas(); canvas.drawRGB(02, 02, 150); fingerx = (x - (Gball.getWidth() / 2)); fingery = (y - (Gball.getHeight() * 2)); for (int i = 0; i &lt; balls.size(); i++) { // here... ballX[i] = i * 155; canvas.drawText("" + score, 40, 100, paint); canvas.drawBitmap(balls.get(i), ballX[i], ChangingY[i], null); </code></pre> <p>Error is:</p> <pre><code>FATAL EXCEPTION: Thread-9140 java.lang.ArrayIndexOutOfBoundsException: length=4; index=4 at com.example.mygame.GFXSurface$GameSurface.run(GFXSurface.java:199) at java.lang.Thread.run(Thread.java:864) </code></pre> <p>I know index should be 5 here but if it is than application doesn't even start</p> <p>OnResume:</p> <pre><code>@Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); ourSurfaceView.resume(); } public void resume() { isRunning = true; ourThread = new Thread(this); ourThread.start(); } </code></pre> <p>Run method:</p> <pre><code>@Override public void run() { for (int j = 0; j &lt; 4; j++) { balls.add(j, RandomBall()); } Paint paint = new Paint(); paint.setColor(Color.RED); paint.setTextSize(100); paint1.setStyle(Style.FILL); paint1.setColor(Color.RED); while (isRunning) { if (!ourHolder.getSurface().isValid()) continue; Canvas canvas = ourHolder.lockCanvas(); canvas.drawRGB(02, 02, 150); fingerx = (x - (Gball.getWidth() / 2)); fingery = (y - (Gball.getHeight() * 2)); for (int i = 0; i &lt; balls.size(); i++) { ballX[i] = i * 155; canvas.drawText("" + score, 40, 100, paint); canvas.drawBitmap(balls.get(i), ballX[i], ChangingY[i], null); if (x != 0 &amp;&amp; y != 0 &amp;&amp; mode == 0) { if (fingerx &lt; 0) { canvas.drawBitmap(Gball, 0, fingery, null); } else if (fingery &lt; 0) { canvas.drawBitmap(Gball, fingerx, 0, null); } else canvas.drawBitmap(Gball, fingerx, fingery, null); checkForCollision(i); } if (ChangingY[i] &lt;= canvas.getHeight()) { ChangingY[i] += 1 * speed; } else if (ChangingY[i] &gt; canvas.getHeight()) { ChangingY[i] = -72; if (speed &lt;= 11) speed += 0.25; removeAndAdd(this, i); } } ourHolder.unlockCanvasAndPost(canvas); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload