0

さて、私はこのコードを以下に持っていますが、実行時エラーが発生し続けており、コードロジックの欠陥であると考えています. メソッドを使用しsetOneOtherPictureて画像を選択し、それを配列に設定して、後で呼び出してshowArtCollectionメソッドに表示しようとしています。2 つのパラメーターが与えられましwhichpRef。誰かがこれで私を助けることができますか? ありがとう。

  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 ();
   }
4

2 に答える 2

0

この方法:

public void setOneOtherPicture (int which, Picture pRef)
{
 this.picArray [which] = new Picture (FileChooser.pickAFile ());
}

FileChooserを呼び出すべきではなく、新しいPictureオブジェクトを作成することさえすべきではありませんが、代わりに、メソッドに既に渡したpRef Pictureオブジェクトを配列に入れるだけです。そうしないと、pRef パラメーターを破棄するだけになり、意味がありません。

于 2013-05-04T22:56:48.867 に答える