Java int无法转换为布尔值
示例代码Java int无法转换为布尔值,java,Java,示例代码 public Student(int y){ idNumber= new CODE(y); } public boolean CODE(){ int studentID= Integer.parseInt(JOptionPane.showInputDialog("Student ID:")); if(idNumber.verifyID(id)){ return true; } return false; } public COD
public Student(int y){
idNumber= new CODE(y);
}
public boolean CODE(){
int studentID= Integer.parseInt(JOptionPane.showInputDialog("Student ID:"));
if(idNumber.verifyID(id)){
return true;
}
return false;
}
public CODE getIdNumber(){
return idNumber.get();
}
public void setIdNumber(CODE idNumber) {
this.idNumber= idNumber;
}
问题
下面是我试图编写的“编辑函数”。这意味着分配新的ID作为IdNumber,但我有转换部分的问题
public void actionPerformed(ActionEvent e){
Student g = (Student)Database.getData();
int a = Integer.parseInt(JOptionPane.showInputDialog("Student ID:"));
g.setIdNumber(a);
}
错误
不兼容类型:int无法转换为Code学生类上的setIdNumber()当前接收一个Code对象,但在actionPerformed()方法中,您正在传入一个int的“a”。尝试使用“new Code(a)”作为setIdNumber()的输入。好吧,
a
是一个int
,但是setIdNumber
采用code
。尝试g.setIdNumber(新代码(a))代码>?除此之外,您显然有一个类代码和一个函数(不是它的构造函数)也称为代码。谢谢您的回答@Marstran谢谢您的回答