Alright I am super confused right now, I am using a piece of code in my program that is 95% similar to another piece I've used in an another program, the only difference is that it worked in the previous program...
it is basically a Image loading class/method and I'm trying to call it in my main class but its not working and the "cannot find symbol - class Image" error occurs.
Where I'm calling the method from my GameImage class:
//STORE IMAGES
private static Image background;
GameImage class:
public class GameImage
{
public static Image loadImage(String imagePathName) {
// All images are loades as "icons"
ImageIcon i = null;
// Try to load the image
File f = new File(imagePathName);
if(f.exists()) { // Success. Assign the image to the "icon"
i = new ImageIcon(imagePathName);
}
else { // Oops! Something is wrong.
System.out.println("\nCould not find this image: "+imagePathName+"\nAre file name and/or path to the file correct?");
System.exit(0);
}
// Done. Either return the image or "null"
return i.getImage();
} // End of loadImages method
}
Where I load the image in main class:
//load the images
background = GameImage.loadImage("Images//background.jpg");
So yeah I dont know why that error keeps popping up because ive used that exact same code structure and GameImage class in another program... hmm
Any help would be great thanks :)
You lack the Image
import statement.
Import the Image
class and you should be fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.