Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling parameters

 
Alix Ollivier
Ranch Hand
Posts: 71
Java Linux Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to make a sprite render in a window, but I have a problem with the arguments of the render() method. My problem is that when I call the render() method, I do it like this:
However, the render method source code is like this:

This arrangement brings up an error. How can I make calling the method work?

Thanks in advance.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don’t you pass a reference to the Graphics object to the render() method? mySprite.render(g);
 
Campbell Ritchie
Sheriff
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And does the Graphics class have a renderAnimation method?
 
Alix Ollivier
Ranch Hand
Posts: 71
Java Linux Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To your post one, this is the error I get if I do that.




To your post 2, drawAnimation is the equivalent. I hope.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is not an error, but an Exception. I don’t think you have posted the code where it occurred. It would appear you are trying to get more elements out of an ArrayList than you put in.
 
Alix Ollivier
Ranch Hand
Posts: 71
Java Linux Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my whole code. See anything odd? I'm fine with comments about class design, but please try and help me with the exception.




 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error message is telling you exactly what's wrong:



At line 412 of Animation.java, you're callng ArrayList's get() method, and trying to get the first element (at index 0) of an ArrayList that has 0 elements (is empty).

So you need to either a) recognize that the list is empty, and not try to get something from it or b) put something into the list so that you can get it out.

If you're thinking the list should have something in at that point and don't know why it doesn't, add a bunch of println() statements so you can see exactly what your code is doing.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, please don't post code with big chunks commented out. The less irrelevant junk in your code, the easier it is to read and the better the chances that somebody will be willing and able to help you with it.
 
Alix Ollivier
Ranch Hand
Posts: 71
Java Linux Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Woops! My bad. I accidentally forgot to initialize the frames in the Sprite, meaning there were none, and that caused an error. Also, Jeff, I'll put in smaller code next time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic