Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with animation

 
levi sleight
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok so im trying to animate so that one picture apears then another apears, heres my code:


class 1:


class 2:



class 3:



im using java 1.7, the output should be a backround image then a picture of a face that switches to a different picture of a face

the error im getting is:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at animation.getscene(animation.java:56)
at animation.getImage(animation.java:50)
at loadimage.draw(loadimage.java:61)
at loadimage.movieLoop(loadimage.java:52)
at loadimage.run(loadimage.java:36)
at loadimage.main(loadimage.java:11)

sorry if its little explanation, but if there any help you could give, it will be much appreciated.
 
B Smith
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simply, you're allowing your indexing variable to move beyond the end of your scenes array:

In line 39 of animation.java you need to prevent this - something like:

 
levi sleight
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
naw, that doesnt work, now it just opens then sits there, no animation
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> naw, that doesnt work,

with that change, do you still get the error from your original post?

> now it just opens then sits there, no animation

a new problem?
 
levi sleight
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no, i dont get the original error, and yess i think its a new error
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> and yess i think its a new error

if there's no error message then its a bug in the code.

the code comes up in several places via google so I'd suggest you contact the author
to see if there's a fix, or perhaps you've added/tweaked something that broke the code.
 
levi sleight
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... well i dint tweak anything, so i must not have copyed it correctky
 
amr talaat
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
development games in java book ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic