运行项目时出错

时间:2012-04-23 14:22:25

标签: java java-ee playframework

An unexpected error occured caused by exception IllegalArgumentException:
Expecting collection type [[Lmodels.Question;]

当我在浏览器上运行整个项目时,localhost中会出现此错误。我不明白错误,我检查了以某种方式链接到类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;
        }

}

1 个答案:

答案 0 :(得分:1)

此错误表示您在某处将Question[]类型的字段注释为@OneToMany@ManyToMany

您应该使用List<Question>之类的集合类型,因为@OneToMany@ManyToMany只能放在集合类型的字段上。