好吧,所以我有下面的代碼,我不斷收到運行時錯誤,我在考慮它在代碼邏輯中的缺陷。我正在嘗試使用setOneOtherPicture
方法來選取圖片並將其設置爲一個數組,以便稍後調用以顯示在showArtCollection
方法中。我已經給出了兩個參數which
和pRef
。有人可以幫我弄這個嗎?謝謝。我的代碼中的Java邏輯
public class House
{
String owner;
Picture pRef;
Picture favPic;
Picture [] picArray = new Picture [3];
public void showArtCollection()
{
ArtWall aWall = new ArtWall(600,600);
aWall.copyPictureIntoWhere(favPic,250,100);
aWall.copyPictureIntoWhere(pRef,51,330);
aWall.copyPictureIntoWhere(pRef,151,330);
aWall.copyPictureIntoWhere(pRef,351,280);
aWall.show();
}
public void setOneOtherPicture (int which, Picture pRef)
{
this.picArray [which] = new Picture (FileChooser.pickAFile());
}
public static void main (String [] args)
{
House PhDsHouse = new House ("Mad PH.D.");
Picture favPic = new Picture();
Picture pRef = new Picture();
PhDsHouse.setOneOtherPicture (0, pRef);
PhDsHouse.setOneOtherPicture (1, pRef);
PhDsHouse.setOneOtherPicture (2,pRef);
PhDsHouse.showArtCollection();
}
什麼例外?請發佈整個異常消息。涉及哪些代碼行?異常消息應該告訴你這一點,然後你必須通過代碼中的註釋或類似的東西來向我們表明這一點。 – 2013-05-04 22:54:48
這個問題是非常相似的http://stackoverflow.com/questions/16377626/nonstatic-variable-pref-cannot-be-referenced-from-a-static-context/16378457#16378457 – Bill 2013-05-04 22:57:44
這是一個家庭作業? – Bill 2013-05-04 22:58:25