传递要序列化的对象java

时间:2015-08-13 16:39:02

标签: java arrays object serialization

我已经搜索了很多试图解决这个问题的网页,但我很挣扎。我不希望有人为我修理它,我只是希望有人指出我正确的方向请:)。我的问题是双重的,我有一系列的对象,我想将每个对象传递给我的Teams类,以便可以保存团队名称。此代码无法编译,错误关注行:
"团队(MainmenuTest [])teamName(){"

错误是' .class'预期 其次是 &#39 ;;'预期

我可以在我的Teams类中创建对象时使用序列化(如果我注释掉传递对象的代码),并且它确实在我指定的目录中创建.ser文件。

以下是代码片段:

:START_ID,:TYPE,:END_ID<br />
2180757,has_precise_ingredient,2192<br />
3025929,has_precise_ingredient,2192<br />
3032289,has_precise_ingredient,2192<br />
3032297,has_precise_ingredient,2192<br />
3280612,has_precise_ingredient,2192<br />

这是MainmenuTest代码:

public class Teams implements java.io.Serializable{

  public Teams(){

    // constructor
    MainmenuTest[] teamName;
    Teams(MainmenuTest[]) teamName() {
      this.teamName = teamName;
    }
  }



   public String name;
   public String address;
   public transient int SSN;
   public int number;
   public void mailCheck()
   {
      System.out.println("Mailing a check to " + name + " " + address);
   }
} // end Teams class



public class premierLeagueClubs{

  public String club;
  Teams[] teamName = new Teams[19];
  premierLeagueClubs f = new premierLeagueClubs();
  Teams t = new Teams(f,teamName);


public String arsenal(){

  teamName[0].club = "Arsenal";

System.out.println("You are the new manager of" + club);
return club;
} // end method arsenal

1 个答案:

答案 0 :(得分:-1)

Teams(MainmenuTest[]) teamName() {

您的构造函数格式不正确。你给它一个类类型,并声明它是一个数组,但没有命名它。然后你给

teamName()

直接在构造函数之后,它不属于它。

在这种情况下,正确的构造函数将是

Teams(MainmenuTest[] teamNameArray){
    this.teamName = teamNameArray;
}

此外,您在构造函数中有一个构造函数:

public Teams(){                                           <---- Constructor

    // constructor
    MainmenuTest[] teamName;
    Teams(MainmenuTest[]) teamName() {                    <---- Constructor
      this.teamName = teamName;
    }
  }

这些应该分为两个:

    MainmenuTest[] teamName;
    Teams(MainmenuTest[] teamNameArray)  {                    
      this.teamName = teamNameArray;
    }
    Teams(){

    }