Java 没有调用另一个类中的方法?
好吧,我现在非常困惑,我在我的程序中使用的一段代码与我在另一个程序中使用的另一段代码95%相似,唯一的区别是它在前一个程序中工作 它基本上是一个图像加载类/方法,我试图在我的主类中调用它,但它不起作用,并且出现了“找不到符号-类图像”错误 在这里,我从GameImage类调用该方法:Java 没有调用另一个类中的方法?,java,image,class,object,methods,Java,Image,Class,Object,Methods,好吧,我现在非常困惑,我在我的程序中使用的一段代码与我在另一个程序中使用的另一段代码95%相似,唯一的区别是它在前一个程序中工作 它基本上是一个图像加载类/方法,我试图在我的主类中调用它,但它不起作用,并且出现了“找不到符号-类图像”错误 在这里,我从GameImage类调用该方法: //STORE IMAGES private static Image background; public class GameImage { public static Image loadImage
//STORE IMAGES
private static Image background;
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
}
游戏图像类:
//STORE IMAGES
private static Image background;
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类。。。嗯
任何帮助都将非常感谢:)您缺少
图像
导入语句
导入
图像
类,您应该会很好。我的导入是:Import java.awt.BorderLayout;导入java.awt.Canvas;导入java.awt.Color;导入java.awt.Dimension;导入java.awt.Graphics;导入java.awt.image.BufferStrategy;导入java.awt.image.buffereImage;导入javax.swing.JFrame;导入javax.swing.*;与我的其他程序类似,所以我不太确定这是否会是一个导入问题?没关系,你是对的,我忘了导入java.awt.*谢谢:)