This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes problem with animation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problem with animation" Watch "problem with animation" New topic
Author

problem with animation

levi sleight
Greenhorn

Joined: Sep 19, 2012
Posts: 19
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

Joined: Oct 13, 2012
Posts: 6
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

Joined: Sep 19, 2012
Posts: 19
naw, that doesnt work, now it just opens then sits there, no animation
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: Sep 19, 2012
Posts: 19
no, i dont get the original error, and yess i think its a new error
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: Sep 19, 2012
Posts: 19
... well i dint tweak anything, so i must not have copyed it correctky
amr talaat
Greenhorn

Joined: Sep 02, 2012
Posts: 19
development games in java book ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with animation