簡體   English   中英

我的另一個類的方法沒有被調用?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM