2012-04-23 5 views
1
An unexpected error occured caused by exception IllegalArgumentException: 
Expecting collection type [[Lmodels.Question;] 

Эта ошибка появляется в локальном хосте, когда я запускаю весь проект в браузере. Я не понимаю ошибку, я проверил все другие классы, связанные с классом Вопрос так или иначе, но ошибок не было, весь код не имеет ошибок компиляции.Ошибка при запуске проекта

Это класс модели Вопрос:

package models; 

    import play.*; 
    import play.db.jpa.*; 

    import javax.persistence.*; 

    import java.util.*; 


    @Entity 
    public class Question extends Model{ 
    public int ExerciseID; 
    public String theQuest; 
    public int marks; 

    public String [] choices; 
    @ManyToOne 
    public Exercise myExercise; 
    @OneToOne (mappedBy="question") 
    public ModelAn modelAnswer; 


    public Question (Exercise e, String quest,String [] aofc,int mark){ 

     if(myExercise.noOfQuest<50){ 
      int j = 0; 
     if (quest != null){ 
     for(int i = 0;i<myExercise.questions.length;i++){ 

      String tempquestion = myExercise.questions[i].theQuest; 
     if (quest.equals(tempquestion)){ 

      j++; 
     }} 
      if(j == 0){ 
      myExercise = new Exercise(e.CreatorID,e.tutID,e.noOfQuest); 
      myExercise.setPeopleAnswered(e.getPeopleAnswered()); 

      theQuest = quest; 
      while (aofc.length<=5){ 
       this.choices[0] = aofc[0]; 
       this.choices[1] = aofc[1]; 
       this.choices[2] = aofc[2]; 
       this.choices[3] = aofc[3]; 
       this.choices[4] = aofc[4]; 

      } 
      this.marks = mark; 
      } 

      } 

     else{ 
      System.out.println("no question was entered please enter a  question"); 
     }}else{ 
      System.out.println("the max no of questions was exceeded"); 
     } 


    } 

    public void addChoices(Question theQuest,String choice1 , String choice2, String choice3, String choice4, String choice5){ 

     String [] tempchoices = new String[5]; 
     tempchoices[0] = choice1; 
     tempchoices[1] = choice2; 
     tempchoices[2] = choice3; 
     tempchoices[3] = choice4; 
     tempchoices[4] = choice5; 
     int j = 0; 
     for(int i = 1; i <= 5;i++){ 

      if(tempchoices[i] != null){ 
       j++; 
      } 
     } 
     if(j<2){ 
      System.out.println("the options entered are less than 2"); 
     } 
     else{ 

      theQuest.choices[0] = choice1; 
      theQuest.choices[1] = choice2; 
      theQuest.choices[2] = choice3; 
      theQuest.choices[3] = choice4; 
      theQuest.choices[4] = choice5; 
     } 


    } 



    public ModelAn getModelAnswer() { 
     return modelAnswer; 
    } 

    public void setModelAnswer(ModelAn modelAnswer) { 
        this.modelAnswer = modelAnswer; 
    } 



     public String getTheQuest() { 
      return theQuest; 
     } 

     public void setTheQuest(String theQuest) { 
      this.theQuest = theQuest; 
     } 

     public int getMarks() { 
      return marks; 
     } 

     public void setMarks(int marks) { 
      this.marks = marks; 
     } 

     public String[] getChoices() { 
      return choices; 
     } 

     public void setChoices(String[] choices) { 
      this.choices = choices; 
     } 

     public Exercise getMyExercise() { 
      return myExercise; 
     } 

     public void setMyExercise(Exercise myExercise) { 
      this.myExercise = myExercise; 
     } 

} 
+4

Предоставьте стек и файл класса, который генерирует стек. – mcfinnigan

ответ

1

Эта ошибка означает, что аннотированный поле типа Question[] в @OneToMany или @ManyToMany где-то.

Вместо этого вы должны использовать тип коллекции, такой как List<Question>, потому что @OneToMany и @ManyToMany могут быть помещены только в поля типов сбора.

+0

Почему мне нужно изменить список? – hadeer

+0

@hadeer: Обновлено. – axtavt

Смежные вопросы