Java.lang.NoSuchMethodException given run reflection:. Com.wang.reflect.Student4 <init> ()

{class fieldDemo01 public 
public static void main (String [] args) throws Exception {
// obtained by using the reflection member variables // 1 , to obtain the Student class bytecode files Class clazz = Student4. class; // 2 , Get object constructor bytecode objects, and then create an object class students the constructor clazz.getConstructor = CON () ; Student4 STU = (Student4) con.newInstance () ; Student4 STU1 = (Student4) clazz.getConstructor () the newInstance (. ) ; // second writing program chain // 3 , student object set each attribute value the System. Out.println (STU) ; } } class Student4 { public String name ;












int Private Age ; @Override public String toString () { return "Student4 {" + "name = '" + name + ' \ ' ' + ", Age =" + Age + '}' ; } }










Exception in Thread "main "java.lang.NoSuchMethodException:. com.wang.reflect.Student4 <init>this error can add constructor with no arguments class solve Student4

Guess you like

Origin www.cnblogs.com/wyj96/p/11928406.html