0

I have a class that has this 2 constructors:

public Conferencia(String nomeConferencia, 
                   String localizacaoConferencia, 
                   int anoConferencia, 
                   int mesConferencia, 
                   int diaConferencia) 
{
    this.nomeConferencia = nomeConferencia;
    this.localizacaoConferencia = localizacaoConferencia;
    this.anoConferencia = anoConferencia;
    this.mesConferencia = mesConferencia;
    this.diaConferencia = diaConferencia;
    this.membroComiteOrganizacao = new MembroComiteOrganizacao[100];
    this.membroComitePrograma = new MembroComitePrograma[100];
    this.idConferencia = contadorConferencias++;
}


public Conferencia(String nomeConferencia, 
                   String localizacaoConferencia, 
                   int anoConferencia, 
                   int mesConferencia, 
                   int diaConferencia, 
                   MembroComiteOrganizacao[] membroComiteOrganizacao) 
{
    this.nomeConferencia = nomeConferencia;
    this.localizacaoConferencia = localizacaoConferencia;
    this.anoConferencia = anoConferencia;
    this.mesConferencia = mesConferencia;
    this.diaConferencia = diaConferencia;
    this.membroComiteOrganizacao = membroComiteOrganizacao;
    this.idConferencia = contadorConferencias++;
}

MembroComiteOrganizacao constructor is like this:

public MembroComiteOrganizacao(int papelMembro, 
                               String memberName, 
                               String memberEmail, 
                               String memberInstituicao) 
{
    super(memberName, memberEmail, memberInstituicao);
    this.papelMembro = papelMembro;

}

In main, to not have to insert always data if i create something like this:

static Conferencia[] conferencias = {new Conferencia("Congresso 1","Abrantes",2012,1,2)};

All is ok.

But now I want to insert in that same constructor data regarding MembroComiteOrganização. I've done:

static Conferencia[] conferencias = {new Conferencia("Congresso 1","Abrantes",2012,1,2,new MembroComiteOrganizacao(1,"Regina Kareem Obrien","[email protected]","Casa da Criança de Tires"))};

but it gives me error.

Can someone explain-me what I'm doing wrong?

UPDATE

done

static Conferencia[] conferencias = {new Conferencia("Congresso 1","Abrantes",2012,1,2,new MembroComiteOrganizacao[1](1,"Regina Kareem Obrien","[email protected]","Casa da Criança de Tires"))};

and the error now is ')' expected

0

3 Answers 3

2

If that is really the only constructor you have in your Conferencia class, then even your first code snipped would fail, since the MembroComiteOrganizacao parameter is not optional and you are not passing value to it.

The other one fails because that parameter is an array, and you are passing a single object.

If you define the last parameter as MembroComiteOrganizacao... membroComiteOrganizacao instead of MembroComiteOrganizacao[] membroComiteOrganizacao (i.e. you use ... instead of []), both your code snippets should work.

Sign up to request clarification or add additional context in comments.

3 Comments

done static Conferencia[] conferencias = {new Conferencia("Congresso 1","Abrantes",2012,1,2,new MembroComiteOrganizacao[1](1,"Regina Kareem Obrien","[email protected]","Casa da Criança de Tires"))}; and now the error is ')' expected
If you don't want to change your constructor to use ... instead of [], then you have to pass the following as the last parameter: new MembroComiteOrganizacao[]{new MembroComiteOrganizacao(1,"Regina Kareem Obrien","[email protected]","Casa da Criança de Tires")}
Btw, if you do replace [] with ... in your constructor, then you can remove the first one (that does not take the last parameter) as the ... tells Java the parameter is optional - so Java treats it as an array which can have 0 to many elements (depending on how many MembroComiteOrganizacao instances you pass to it). So that may be the thing you want to do.
1

while creating static Conferencia[] conferencias at index 0, the c'tor is not closed.

Comments

0

Your types don't match up, your Conferencia constructor takes an array of MembroComiteOrganizacao, but you give it one instance, not an array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.