[英]My method from another class is not being called?
好吧,我现在非常困惑,我在程序中使用的一段代码与我在另一个程序中使用的另一段代码有95%的相似性,唯一的区别是它在先前的程序中有效...
它基本上是一个图像加载类/方法,我试图在主类中调用它,但是它不起作用,并且发生“找不到符号-类图像”错误。
我从GameImage类中调用方法的位置:
//STORE IMAGES
private static Image background;
GameImage类:
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
}
我在主类中加载图像的位置:
//load the images
background = GameImage.loadImage("Images//background.jpg");
所以是的,我不知道为什么这个错误不断弹出,因为我在另一个程序中使用了完全相同的代码结构和GameImage类。
任何帮助将不胜感激:)
您缺少Image
导入语句。
导入Image
类,就可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.