Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  cannot find symbol method  (Read 3409 times)
0 Members and 1 Guest are viewing this topic.
Offline h3ckboy

JGO Coder


Medals: 5



« Posted 2009-01-22 21:50:30 »

hey I have 2 programs both wiht identical code. one does not work and one does.
here is the code for the one that is not working:

import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;

public class Actor {
   protected int x,y;
   protected int width, height;
   protected String[] spriteNames;
   protected int currentFrame;
   protected int frameSpeed;
   protected int t;
   protected Stage stage;
   protected SpriteCache spriteCache;
   protected boolean markedForRemoval;
   
   public Actor(Stage stage) {
      this.stage = stage;
      spriteCache = stage.getSpriteCache();
      currentFrame = 0;
      frameSpeed = 1;
      t=0;
   }
   
   public void remove() {
      markedForRemoval = true;
   }
   
   public boolean isMarkedForRemoval() {
      return markedForRemoval;
   }
   
   public void paint(Graphics2D g){
      // BufferedImage img = spriteCache.getSprite(spriteNames[currentFrame]);
      g.drawImage( spriteCache.getSprite(spriteNames[currentFrame]), x,y, stage );//it cannot find this method
   }
   
   public int getX()  { return x; }
   public void setX(int i) {   x = i; }

   public int getY() {   return y; }
   public void setY(int i) { y = i; }
   
   public int getFrameSpeed() {return frameSpeed;   }
   public void setFrameSpeed(int i) {frameSpeed = i;   }
   
   
   public void setSpriteNames(String[] names) {
      spriteNames = names;
      height = 0;
      width = 0;
      for (int i = 0; i < names.length; i++ ) {
        BufferedImage image = spriteCache.getSprite(spriteNames);
        height = Math.max(height,image.getHeight());
        width = Math.max(width,image.getWidth());
      }
   }         
   
   public int getHeight() { return height; }
   public int getWidth() {   return width;   }
   public void setHeight(int i) {height = i;   }
   public void setWidth(int i) {   width = i;   }

   public void act() {
      t++;
      if (t % frameSpeed == 0){
         t=0;
        currentFrame = (currentFrame + 1) % spriteNames.length;
      }
   }
   
   public Rectangle getBounds() {
      return new Rectangle(x,y,width,height);
   }
   
   public void collision(Actor a){
      
   }
}
And here is the method it is calling from:

import java.awt.image.BufferedImage;
import java.net.URL;
import java.util.HashMap;

import javax.imageio.ImageIO;

public class SpriteCache {
   private HashMap sprites;
   
   public SpriteCache() {
      sprites = new HashMap();
   }
   
   private BufferedImage loadImage(String name) {
      URL url=null;
      try {
         url = getClass().getClassLoader().getResource(name);
         return ImageIO.read(url);
      } catch (Exception e) {
         System.out.println("No se pudo cargar la imagen " + name +" de "+url);
         System.out.println("El error fue : "+e.getClass().getName()+" "+e.getMessage());
         System.exit(0);
         return null;
      }
   }
   
   public BufferedImage getSprite(String name) {
      BufferedImage img = (BufferedImage)sprites.get(name);
      if (img == null) {
         img = loadImage(name);
         sprites.put(name,img);
      }
      return img;
   }
}
Any help would be deaply appreciated.

Thx in advance
Offline steveyO
« Reply #1 - Posted 2009-01-23 01:37:37 »

Cant see if its not working as you havent posted the code for your Stage class.

The only other compilation error (aside from the missing Stage class) is in the line:   
1  
BufferedImage image = spriteCache.getSprite(spriteNames);

I guess you mean:
1  
BufferedImage image = spriteCache.getSprite(names[i]);

https://play.google.com/store/apps/details?id=com.bullsquared.alggame Annoying Little Gits (Android)
www.bullsquared.com   Play java (applet) games! www.chessclockpro.com Free Online Chess Clock
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #2 - Posted 2009-01-23 08:17:33 »

i get the same error. i will post Stage but it wont help that much becausee it is just an interface. but here it is:
import java.awt.image.ImageObserver;

public interface Stage{
    public static final int WIDTH=640;
    public static final int HEIGHT=480;
    public static final int SPEED=10;
    public SpriteCache getSpriteCache();
    public Player getPlayer();
}

the exact error I get form the compiler is this:
cannot find symbol - method drawImage(java.awt.image.BufferedImage,int,int,Stage)
Thanks for the fast reply.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #3 - Posted 2009-01-23 16:17:43 »

This Graphics.drawImage method expects an ImageObserver instead of your Stage object.
Your Stage interface is not an ImageObserver. You import it, but that is just a compiler directive, your code does nothing with the import.

Try to change your line
1  
g.drawImage( spriteCache.getSprite(spriteNames[currentFrame]), x,y, stage );


to

1  
g.drawImage( spriteCache.getSprite(spriteNames[currentFrame]), x, y, null );

Offline h3ckboy

JGO Coder


Medals: 5



« Reply #4 - Posted 2009-01-23 16:21:18 »

YOU ARE AMAZING!!!
I have been stumped for moths on this. yes, finally Ia m able to continue on witht he game. i am soo glad I found this forum.

thank you.
Offline Mr_Light

Senior Member




shiny.


« Reply #5 - Posted 2009-01-24 13:19:38 »

Are you using a decent IDE? www.eclipse.org www.netbeans.org www.intellij.com ?

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #6 - Posted 2009-01-24 17:27:01 »

I use BlueJ Smiley
and what you you mean by "descent" most compilers are good. only requirement is that it doesnt involve typing "javac" into a compiler. hehe
Offline Mr_Light

Senior Member




shiny.


« Reply #7 - Posted 2009-01-24 18:23:58 »

BlueJ is too new for me  Tongue

By decent I mean it's up with today's standard and not '84, when people where still happy doing awkward things in a console.
In this particular case I'm refering to error highlighting, the compiler will tell you the line and char of where the offending token is but in any decent IDE it will show you as you type much like a Text editors spell check. Which should have allowed you to pick out the mistake yourself. Moreover it will probably say exactually the same replied here albeit a maybe little more cryptic.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #8 - Posted 2009-01-24 19:09:12 »

It sayed where the error was as I pointed out here

quote:
public void paint(Graphics2D g){
      // BufferedImage img = spriteCache.getSprite(spriteNames[currentFrame]);
      g.drawImage( spriteCache.getSprite(spriteNames[currentFrame]), x,y, stage );//it cannot find this method
   }
   
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (11 views)
2014-07-30 21:08:39

Riven (21 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (29 views)
2014-07-23 21:07:15

Riven (30 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!