- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
嗨,我正在尝试编写一个方法,该方法循环遍历数组列表以检查数组列表中的 Sprite 是否已被触摸,如果是则删除它们。我已经编写了这个方法,但是当我单击 Sprite 时,它们会停止并振动,然后游戏崩溃。下面提供了 Logcat
onTouchEvent
public class GameView extends SurfaceView implements SurfaceHolder.Callback {
/* Member (state) fields */
private GameLoopThread gameLoopThread;
private Paint paint; //Reference a paint object
/** The drawable to use as the background of the animation canvas */
private Bitmap mBackgroundImage;
private Sprite sprite;
int arraySize;
private int hitCount;
private ArrayList<Sprite> spritesArrayList;
private GameView gameView;
int numberofsprites = 5;
int finalScore;
private boolean gameOver;
/* For the countdown timer */
private long startTime ; //Timer to count down from
private final long interval = 1 * 1000; //1 sec interval
private CountDownTimer countDownTimer; //Reference to class
private boolean timerRunning = false;
private String displayTime; //To display time on the screen
private Bitmap spritebmp;
public GameView(Context context) {
super(context);
// Focus must be on GameView so that events can be handled.
this.setFocusable(true);
// For intercepting events on the surface.
this.getHolder().addCallback(this);
mBackgroundImage = BitmapFactory.decodeResource(this.getResources(),
R.drawable.background2);
spritesArrayList= new ArrayList<Sprite>(numberofsprites);
}
public void surfaceCreated(SurfaceHolder holder) {
mBackgroundImage = Bitmap.createScaledBitmap(mBackgroundImage, getWidth(), getHeight(), true);
ResetGame();
gameLoopThread = new GameLoopThread(this.getHolder(), this);
gameLoopThread.running = true;
gameLoopThread.start();
}
//To initialise/reset game
private void ResetGame(){
gameOver = false;
hitCount = 0;
/* Set paint details */
paint = new Paint();
paint.setColor(Color.WHITE);
paint.setTextSize(20);
//Set timer
startTime = 60;//Start at 10s to count down
//Create new object - convert startTime to milliseconds
countDownTimer=new MyCountDownTimer(startTime*1000,interval);
countDownTimer.start();//Start it running
timerRunning = true;
for (int i = 0; i < numberofsprites; i++)
{
sprite = new Sprite(this);
spritesArrayList.add(new Sprite(this));
}
}
//This class updates and manages the assets prior to drawing - called from the Thread
public void update(){
sprite = new Sprite(this);
if (gameOver != true) {
for (int i = 0; i < numberofsprites; i++)
{
sprite = spritesArrayList.get(i);
sprite.update();
}
}
}
/**
* To draw the game to the screen
* This is called from Thread, so synchronisation can be done
*/
public void doDraw(Canvas canvas) {
Paint textPaint = new Paint();
canvas.drawBitmap(mBackgroundImage, 0, 0, null);
//Draw all the objects on the canvas
canvas.drawText("The Game ",5,25, paint);
canvas.drawText("Score: " + hitCount, 5, 50, paint);
canvas.drawText("Time: " +displayTime, 5, 75, paint);
//Loop for sprite creation
for (int i = 0; i < spritesArrayList.size(); i++)
{
sprite = spritesArrayList.get(i);
sprite.draw(canvas);
}
if (gameOver == true)
{
canvas.drawText("Final Score: "+finalScore, 5,100, paint);
int width = this.getMeasuredWidth()/2;
int height = this.getMeasuredHeight()/2;
textPaint.setTextAlign(Align.CENTER);
canvas.drawText("GAME OVER - PRESS BACK BUTTON TO RETURN", width, height, textPaint);
}
}
public int getHitCount()
{
return hitCount;
}
//To be used if we need to find where screen was touched
public boolean onTouchEvent(MotionEvent event) {
if (!gameOver)
{
Iterator<Sprite> i = spritesArrayList.iterator();
while (i.hasNext()) {
sprite = i.next();
if (sprite.wasItTouched(event.getX(), event.getY())) {
i.remove();
sprite = new Sprite(this);
sprite.update();
hitCount++;
}
}
}
return true;
}
public void surfaceDestroyed(SurfaceHolder holder) {
gameLoopThread.running = false;
// Shut down the game loop thread cleanly.
boolean retry = true;
while(retry) {
try {
gameLoopThread.join();
retry = false;
} catch (InterruptedException e) {}
}
}
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
private class MyCountDownTimer extends CountDownTimer {
public MyCountDownTimer(long startTime, long interval) {
super(startTime, interval);
}
public void onFinish() {
displayTime = "Times Over!";
finalScore = hitCount;
gameOver = true;
timerRunning = false;
countDownTimer.cancel();
}
public void onTick(long millisUntilFinished) {
displayTime = " " + millisUntilFinished / 1000;
}
}//End of MyCountDownTimer
public void updateEasy()
{
this.gameView=gameView;
numberofsprites = 20;
}
public void updateMedium()
{
this.gameView=gameView;
numberofsprites = 15;
}
public void updateHard()
{
this.gameView=gameView;
numberofsprites = 5;
}
}
Logcat
05-06 14:36:41.613: E/AndroidRuntime(1639): FATAL EXCEPTION: main
05-06 14:36:41.613: E/AndroidRuntime(1639): Process: cct.mad.lab, PID: 1639
05-06 14:36:41.613: E/AndroidRuntime(1639): java.lang.IllegalStateException
05-06 14:36:41.613: E/AndroidRuntime(1639): at java.util.ArrayList$ArrayListIterator.remove(ArrayList.java:589)
05-06 14:36:41.613: E/AndroidRuntime(1639): at cct.mad.lab.GameView.onTouchEvent(GameView.java:166)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.View.dispatchTouchEvent(View.java:7706)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
05-06 14:36:41.613: E/AndroidRuntime(1639): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2068)
05-06 14:36:41.613: E/AndroidRuntime(1639): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1515)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.app.Activity.dispatchTouchEvent(Activity.java:2458)
05-06 14:36:41.613: E/AndroidRuntime(1639): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2016)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.View.dispatchPointerEvent(View.java:7886)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3954)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3833)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3525)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3426)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3582)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3426)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5602)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5582)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5553)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5682)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:5655)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:5701)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.Choreographer.doFrame(Choreographer.java:542)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.os.Handler.handleCallback(Handler.java:733)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.os.Handler.dispatchMessage(Handler.java:95)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.os.Looper.loop(Looper.java:136)
05-06 14:36:41.613: E/AndroidRuntime(1639): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-06 14:36:41.613: E/AndroidRuntime(1639): at java.lang.reflect.Method.invokeNative(Native Method)
05-06 14:36:41.613: E/AndroidRuntime(1639): at java.lang.reflect.Method.invoke(Method.java:515)
05-06 14:36:41.613: E/AndroidRuntime(1639): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-06 14:36:41.613: E/AndroidRuntime(1639): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-06 14:36:41.613: E/AndroidRuntime(1639): at dalvik.system.NativeStart.main(Native Method)
05-06 14:36:41.633: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:41.633: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:41.633: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:41.633: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:41.633: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:41.703: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:41.703: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:41.703: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:41.713: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:41.713: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:41.763: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:41.763: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:41.763: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:41.783: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:41.783: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:41.823: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:41.823: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:41.823: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:41.823: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:41.823: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:41.863: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:41.863: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:41.873: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:41.873: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:41.873: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:41.903: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:41.903: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:41.903: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:41.903: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:41.913: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:41.933: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:41.933: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:41.933: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:41.933: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:41.943: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:41.953: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:41.953: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:41.953: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:41.953: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:41.953: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:41.963: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:41.963: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:41.963: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:41.973: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:41.973: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:41.993: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:41.993: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:42.023: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:42.023: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:42.043: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:42.063: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:42.063: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:42.073: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:42.073: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:42.073: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:42.073: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:42.083: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:42.083: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:42.083: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:42.083: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:42.113: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:42.113: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:42.113: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:42.113: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:42.123: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:42.143: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:42.143: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:42.143: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:42.143: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:42.153: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:42.193: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:42.243: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:42.243: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:42.243: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:42.253: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:42.253: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:42.263: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:42.263: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:42.263: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:42.263: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:42.323: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:42.323: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:42.333: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:42.333: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:42.333: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:42.523: D/dalvikvm(1639): GC_FOR_ALLOC freed 618K, 66% free 4491K/13092K, paused 159ms, total 163ms
05-06 14:36:42.553: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:42.553: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:42.553: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:42.553: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:42.553: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:42.583: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:42.583: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:42.583: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:42.593: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:42.593: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:42.623: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:42.623: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:42.623: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:42.623: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:42.633: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:42.653: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:42.653: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:42.683: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:42.683: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:42.693: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:42.733: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:42.733: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:42.733: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:42.733: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:42.733: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:42.783: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:42.783: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:42.783: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:42.783: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:42.793: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:42.843: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:42.853: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:42.853: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:42.853: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:42.853: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:42.883: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:42.883: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:42.883: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:42.883: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:42.893: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:42.933: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:42.933: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:42.933: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:42.933: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:42.943: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:43.003: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:43.003: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:43.003: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:43.013: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:43.013: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:43.073: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:43.073: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:43.073: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:43.073: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:43.113: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:43.143: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:43.153: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:43.153: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:43.153: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:43.153: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:43.273: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:43.273: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:43.273: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:43.273: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:43.273: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:43.313: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:43.313: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:43.323: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:43.463: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
05-06 14:36:43.493: W/System.err(1639): at cct.mad.lab.GameLoopThread.run(GameLoopThread.java:50)
05-06 14:36:43.493: W/System.err(1639): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
05-06 14:36:43.503: W/System.err(1639): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
05-06 14:36:43.503: W/System.err(1639): at java.util.ArrayList.get(ArrayList.java:308)
05-06 14:36:43.503: W/System.err(1639): at cct.mad.lab.GameView.update(GameView.java:106)
最佳答案
从 ArrayList 中删除一个元素也会改变 ArrayList 本身的元素数量。你少了一个项目,但你仍然在列表上循环,因为它仍然有相同数量的项目。使用迭代器代替:例如
Iterator<Sprite> i = spritesArrayList.iterator();
while (i.hasNext()) {
sprite = i.next();
if (sprite.wasItTouched(event.getX(), event.getY())) {
i.remove();
sprite = new Sprite(this);
hitCount++;
}
}
关于java - 触摸时从 arrayList 中删除 Sprite - "Invalid index 4, size is 4",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30084529/
我正在尝试向 iOS 应用商店提交更新。我要从 Buzztouch 应用程序转到 Sprite Kit 应用程序。我能够存档 Xcode 项目并提交它。该应用程序的状态为“上传已收到”,但大约一分钟后
我收到了这个奇怪的警告。我不确定是什么原因造成的。 .dia文件扩展名应该表示核心有向图图形文件。我没有添加,应用程序几乎没有用户界面。 最佳答案 我对这个答案并不满意,但我认为它可以帮助人们,直到找
下面用作 Uri 参数的程序集限定字符串在 XAML 中工作,但在代码中使用时会出现错误。 我尝试了各种 UriKind,结果都相同。我该如何解决这个问题? [Test] public void La
我正在开发一个 Angular 应用程序,目的是将其部署到移动设备和 Web 浏览器上。设置表单样式以显示无效输入时,我应该定位 Angular“ng-invalid”类还是 HTML5“:inval
我有一个在 Google App Engine 上运行的应用程序,它是 Android 应用程序的后端。它基本上是 Android 应用程序和在我自己的服务器上运行的 MySQL 数据库之间的桥梁。
我的代码是这样的: func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle,
I need to encrypt using Python with the A256GCM algorithm, and getting back a JWT that I need to
无法成功编译webpack并生成bundle.js文件。据我了解,我的 src_dir 和 dist_dir 变量能够指向正确的路径,但在尝试编译时我仍然始终收到两个错误之一。 配置对象无效。 Web
因此,当我在 postgres 上运行 regexp_matches 时收到一条错误消息,并且无法弄清楚如何通过它。它似乎在 regex101 等 reg_exp 测试站点上运行良好,但不幸的是在实际
这些是我正在使用的导入: import com.novell.ldap.*; import java.io.UnsupportedEncodingException; 我正在尝试进行一个非常简单的密码
在记录器函数的简写情况下,Pylint 提示 Invalid constant name "myprint"(invalid-name)。 # import from utils import get
我试图创建一个HTML输入标签,该标签仅接受以2种格式之一输入的数字,并拒绝所有其他输入。 我只想接受以下格式的数字,包括破折号: 1234-12 和 1234-12-12 注意:不是日期,而是合法的
我一直在尝试使用 Bootstrap 的表单样式处理 AngularJS 的电子邮件验证,并遇到了这个 CSS block 。 input:focus:required:invalid, textar
我正在编写一个程序,以确保我了解如何在 C 中正确实现单向链表。我目前正在哈佛的 CS50 类(class)中学习,并且使用本教程,因为 CS50 人员不解释链接详细列出数据结构:https://ww
此问题与询问同一消息的另一个问题不重复,但在另一个上下文中。这个问题的上下文只是关于上传截图图像和获取消息。 今天,我在将图片上传到 App Store Connect 时收到一条新消息: Inval
我的代码似乎运行良好,但当我滑动以删除 UITableView 中的一行时,应用程序崩溃并显示以下内容: 错误 LittleToDoApp[70390:4116002] *** Terminating
当我尝试发送语音消息时,总是收到无效的url错误。我正在使用Whisper将音频转换为文本,但由于某种原因,我似乎无法将文件传递给Whisper。当我在Java脚本中使用它而不是在TypeScrip中
我正在尝试在 flutter 上对 http 客户端进行单元测试。在模拟 http 和我的存储库类之后: void main() { MockHttpCLient mockHttpCLient;
我正在使用 pandoc 作为一个库,相关的代码片段是: module Lib ( latexDirToTex, latexToTxt ) where import qualified
我正在开发一个(相对简单的)Rails应用程序。我正在使用Devise gem处理用户 session 。每当我导航到localhost:3000/users/sign_in时,我都会看到Devise
我是一名优秀的程序员,十分优秀!