我無法從我的Picture
類訪問String
說明,以便在PhotoViewer
類中使用它。我創建了一個getter方法,所以我不明白爲什麼我得到錯誤試圖從另一個類訪問字符串?
無法找到符號 - 方法getDescription()。
下面是代碼:
/**
* Write a description of class Picture here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Picture extends Attachment
{
protected String description;
protected String height;
protected String width;
/**
* Constructor for objects of class Picture
*/
public Picture(String filename, long size, String description, String height, String width)
{
this.filename = filename;
this.size = size;
this.description = description;
this.height = height;
this.width = width;
}
/**
* Prints out the details of a picture attachment.
*/
public void preview()
{
System.out.println("Filename: " + filename);
System.out.println("Size: " + size);
System.out.println("Description: " + description);
System.out.println("Height: " + height);
System.out.println("Width: " + width);
}
/**
* Getter method that returns the description
*/
public String getDescription()
{
return description;
}
}
/**
* Application to open and view photos
*
* @author Chandler Warren
* @version 12-1-15
*/
public class PhotoViewer extends Application
{
Picture picture;
/**
* Constructor for objects of class PhotoViewer
*/
public PhotoViewer()
{
}
/**
* Abstract method to open the attachment
*/
public void open(Attachment picture)
{
System.out.println("I am the PhotoViewer. You are viewing a picture of " + getDescription());
}
}
New error encountered when trying to initiate picture
應該是'picture.getDescription()'? – JCOC611
而方法參數應該是圖片,而不是附件。無論如何,這個附件類是什麼? –
@HovercraftFullOfEels其實,它應該是Attachment。我跟我的老師檢查過。如果有幫助,我會添加附件類。 –