怎么解决The method getIdcard() is undefined for the type String

如何解决The method getIdcard() is undefined for the type String这事封装对象的代码package cn.itcast.

如何解决The method getIdcard() is undefined for the type String
这事封装对象的代码
package cn.itcast.domain;

public class Student {

private String idcard;
private String examid;
private String name;
private String location;
private double grade;


public String getIdcard() {
return idcard;
}
public void setIdcard(String idcard) {
this.idcard = idcard;
}
public String getExamid() {
return examid;
}
public void setExamid(String examid) {
this.examid = examid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public double getGrade() {
return grade;
}
public void setGrade(double grade) {
this.grade = grade;
}

}
这事操作代码
import cn.itcast.utils.XmlUtils;

public class StudentDao {


public void add(String s){

try {
Document document = XmlUtils.getDocument();

//创建封装学生信息的标签
Element student_tag = document.createElement("student");
student_tag.setAttribute("idcard", s.getIdcard());
student_tag.setAttribute("examid", s.getExamid());

} catch (Exception e) {
throw new RuntimeException(e);
}

}
}
这里的getIdcard()和getExamid()方法会出现The method getIdcard() is undefined for the type String的错误啊!

[解决办法]
将StudentDao改成下面的代码应该就OK了,你试试

Java code
import cn.itcast.utils.XmlUtils;public class StudentDao {    public void add(Student s){        try {            Document document = XmlUtils.getDocument();//创建封装学生信息的标签            Element student_tag = document.createElement("student");            student_tag.setAttribute("idcard", s.getIdcard());            student_tag.setAttribute("examid", s.getExamid());        } catch (Exception e) {            throw new RuntimeException(e);        }    }}