Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes Calling parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Calling parameters" Watch "Calling parameters" New topic
Author

Calling parameters

Alix Ollivier
Ranch Hand

Joined: Jun 04, 2012
Posts: 71

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.


"The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!', but 'That's funny...' "
- Isaac Asimov
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37950
    
  22
Don’t you pass a reference to the Graphics object to the render() method? mySprite.render(g);
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37950
    
  22
And does the Graphics class have a renderAnimation method?
Alix Ollivier
Ranch Hand

Joined: Jun 04, 2012
Posts: 71

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

Joined: Oct 13, 2005
Posts: 37950
    
  22
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

Joined: Jun 04, 2012
Posts: 71

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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Jun 04, 2012
Posts: 71

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling parameters
 
Similar Threads
dynamic datatable binding
How to speed up my site?
Using XDoclet with an IDE
Problem with selectOneMenu
JSF 1.2 Postback