0

I have defined a class that contains properties of a specific answer object The class look like this and is defined inside the class that is trying to use it

protected class Answer {
    String QuestionId = "";
    String AnswerValue = "";
    String Correct = "";
    public String getQuestionId() {
        return QuestionId;
    }
    public void setQuestionId(String arg) {
        QuestionId = arg;
    }
    public String getAnswerValue() {
        return AnswerValue;
    }
    public void setAnswerValue(String arg) {
        AnswerValue = arg;
    }
    public String getCorrect() {
        return Correct;
    }
    public void setCorrect(String arg) {
        Correct = arg;
    }
}

Not sure if the above is OK When I try to use the class I get null pointer errors I'm using it like this

                ArrayList<Answer> answerList = new ArrayList<Answer>();
                for(int a=0;a<answers.getLength(); a++){
                    Element eAnswer = (Element) answers.item(a);
                    Answer anAnswer = new Answer;
                    NodeList answer_nodes = eAnswer.getChildNodes();
                    for (int ian=0; ian<answer_nodes.getLength(); ian++){
                        Node ans_attr = answer_nodes.item(ian);
                        String tag_name = ans_attr.getNodeName();
                        if(tag_name.equalsIgnoreCase("answer")){
                            anAnswer.setAnswerValue(ans_attr.getTextContent());
                        }
                    }
                    answerList.add(anAnswer);
                }

Answer anAnswer = new Answer; gives a compilation error All I'm trying to do is to create a list of answers which have a name value pair for a number of properties

Any guidance on this greatly appreciated - Especially if there is a better way

1 Answer 1

3
Answer anAnswer = new Answer();
Sign up to request clarification or add additional context in comments.

1 Comment

no problem =) mistakes like that are sometimes difficult to find =)

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.