cannot find symbol method

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[i]);
  	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

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:

BufferedImage image = spriteCache.getSprite(spriteNames);

I guess you mean:

BufferedImage image = spriteCache.getSprite(names[i]);

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.

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


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

to


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

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.

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

I use BlueJ :slight_smile:
and what you you mean by “descent” most compilers are good. only requirement is that it doesnt involve typing “javac” into a compiler. hehe

BlueJ is too new for me :stuck_out_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 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
}