如何解决The method getIdcard() is undefined for the type String

qadada 2011-10-23 12:49:00
这事封装对象的代码
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的错误啊!
...全文
931 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
风尘中国 2011-10-23
  • 打赏
  • 举报
回复
将StudentDao改成下面的代码应该就OK了,你试试

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

}
}

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧