-1

メソッドで画像を設定しようとしていsetFavoritePicture (Picture pRef)ます。このメソッドは、メイン メソッドで呼び出されるお気に入りの画像を設定することになっていますが、コンパイラ エラーが発生し続けますnonstatic variable pRef cannot be referenced from a static context。私はJavaに比較的慣れていないので、あなたが私に提供できる助けは非常に高く評価されます

public class House
{
 String owner;
 Picture pRef;
 Picture [] picArray;
 Picture favPic;

 public void showArtCollection ()
  {

   ArtWall aWall = new ArtWall(600,600);
   aWall.copyPictureIntoWhere(favPic,250,100);
   aWall.copyPictureIntoWhere(picArray[0],51,330);
   aWall.copyPictureIntoWhere(picArray[1],151,330);
   aWall.copyPictureIntoWhere(picArray[2],351,280);
   aWall.show();

  }



 public House (String param)
 {

  this.owner = param;
  this.picArray = new Picture [3];
  this.favPic = new Picture (FileChooser.pickAFile ());
  this.picArray [0] = new Picture (FileChooser.pickAFile ());
  this.picArray [1] = new Picture (FileChooser.pickAFile ());
  this.picArray [2] = new Picture (FileChooser.pickAFile ());




 }

public void setFavoritePicture (Picture pRef)
{
 pRef = favPic;
}

public void setOneOtherPicture (int which,Picture pRef)
{

}


public void swapGivenOtherWithFavorite (int which)
 {
  Picture tempSaver;
  tempSaver = pRef;
  pRef = picArray [which];
  picArray [which] = tempSaver;
 }


public void addPicture (Picture pictureAdded)
{
 pRef = pictureAdded;


}

public void showPicture ()
{

 picArray [0].explore ();
 picArray [1].explore ();
 picArray [2].explore ();
 favPic.explore ();


}


public static void main (String [] args)
 {
  House PhDsHouse = new House ("Mad PH.D.");
  PhDsHouse.setFavoritePicture (pRef);
  PhDsHouse.swapGivenOtherWithFavorite (2);
  PhDsHouse.showArtCollection ();


 }

}

4

1 に答える 1