사용자에게 평가의 arraylist를 반환하는이 함수가 있습니다. 모든 평가에는 일련의 질문 목록이 있습니다. 데이터베이스에서 질문을 얻지 만, 사용자에게 assessment 배열을 반환 할 때 questions 배열은 비어 있습니다. 누구든지 질문 배열 채우기를 도울 수 있습니다.데이터가 데이터베이스에서 제대로 반환되지 않았습니다.
참고 : 이 나에게 크기의 예를 제공 우는 내가 코드에서이 Log.v("--", "Questions: " + questions.size());
을.
public ArrayList<Assessment> getAllAsssessments() {
ArrayList<Assessment> assessments = new ArrayList<Assessment>();
Assessment assessment;
String selectQuery = "SELECT * FROM " + TSCYC;
Cursor cursor = database.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
int AssessmentID = cursor.getInt(0);
int childID = cursor.getInt(1);
int doctorID = cursor.getInt(2);
String assessmentDate = cursor.getString(3);
Log.v("--", assessmentDate);
ArrayList<Question> questions = new ArrayList<Question>();
Question q;
assessment = new Assessment(AssessmentID, assessmentDate,
doctorID, childID, questions);
for (int i = 0; i < 90; i++) {
q = new Question("i", (i + 1));
q.setAnswer(cursor.getInt(i + 4));
questions.add(q);
}
Log.v("--", "Questions: " + questions.size());
assessment = new Assessment(AssessmentID, assessmentDate,
doctorID, childID, questions);
assessments.add(assessment);
Log.v("--", "AssessmentQuestions: "
+ assessment.getQuestions().size());
} while (cursor.moveToNext());
}
return assessments;
}
Assessmen 클래스 :
import java.io.Serializable;
import java.util.ArrayList;
public class Assessment implements Serializable {
private static final long serialVersionUID = 1288566422025895376L;
private String date;
private int doctorID, childID, id;
private ArrayList<Question> questions;
public Assessment(int id, String date, int doctorID, int childID,
ArrayList<Question> questions) {
questions = new ArrayList<Question>();
this.id = id;
this.setDate(date);
this.setDoctorID(doctorID);
this.setChildID(childID);
this.setQuestions(questions);
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public int getDoctorID() {
return doctorID;
}
public void setDoctorID(int doctorID) {
this.doctorID = doctorID;
}
public int getChildID() {
return childID;
}
public void setChildID(int childID) {
this.childID = childID;
}
public ArrayList<Question> getQuestions() {
return questions;
}
public void setQuestions(ArrayList<Question> questions) {
this.questions = questions;
}
}
[질문 클래스 :
90,하지만 그 이후 행이, 내가Log.v("--", "AssessmentQuestions: "+assessment.getQuestions().size());
을 할 때 나에게 여기
size: 0
를 제공 내 코드입니다
public class Question implements Serializable{
/**
*
*/
private static final long serialVersionUID = 8703113563916355470L;
private String question;
private int answer, position;
public Question(String question, int position) {
answer = -1;
this.question = question;
this.position = position;
}
public int getAnswer() {
return answer;
}
public void setAnswer(int answer) {
this.answer = answer;
}
public int getPosition() {
return position;
}
public void setPosition(int position) {
this.position = position;
}
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
}
Assesment 생성자는 어떻게 생겼습니까? 물론 모든 것이 괜찮습니까? – pumpkee
실은 Assessment에 'new'가있는 항목이 있습니까? 문제가 될 것이라고 생각합니다. 관계없이 우리는 완전한 (짧은) 프로그램이 필요합니다 –
@RichardTingle 당신이 대답에서 나를 더 설명 할 수 있습니까? –