好吧,所以我有下面的代码,我不断收到运行时错误,我在考虑它在代码逻辑中的缺陷。我正在尝试使用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