gpt4 book ai didi

java - 运行项目时出错

转载 作者:太空宇宙 更新时间:2023-11-04 08:16:45 24 4
gpt4 key购买 nike

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;
}

}

最佳答案

此错误意味着您注释了 Question[] 类型的字段如@OneToMany@ManyToMany某处。

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

关于java - 运行项目时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10282417/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com