• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Calling parameters

 
Ranch Hand
Posts: 71
Mac Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 76842
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don’t you pass a reference to the Graphics object to the render() method? mySprite.render(g);
 
Campbell Ritchie
Marshal
Posts: 76842
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And does the Graphics class have a renderAnimation method?
 
Alix Ollivier
Ranch Hand
Posts: 71
Mac Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 76842
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.




 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You had your fun. Now it's time to go to jail. Thanks for your help tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic