求大佬,关于抛出的NoSuchMethodException异常问题
问题描述:(用ecplise)这是book代码块和test代码块,构造方法和代码都正确,可是一直抛出NoSuchMethodException异常,
public class Book {
private int no;
private String name;
public double price;
public Book() {
super();
}
public Book(int no,double price, String name) {
super();
this.no = no;
this.name = name;
this.price = price;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
@Override
public String toString() {
return "Book [no=" + no + ", name=" + name + ", price=" + price + "]";
}
}
public class BookTest {
public static void main(String[] args) {
try {
Class classBook=Class.forName("com.myimooc.test.Book");
Constructor constructor=classBook.getConstructor(new Class[] {
int.class,Double.class,String.class
});
Book book=(Book)constructor.newInstance(new Object[] {
001,75,"爱的教育"
});
System.out.println(book);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
正在回答
同学你好,如下位置应该使用double,Double是double的包装类,是不一样的哦
祝学习愉快~
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星