下面是程序,目测没错
package com.lshua;
public class TestReflection {
public static void main(String[] args) throws Exception{
String s="Test";
Class c= Class.forName(s);
c.newInstance();
}
}
class Test{
static{
System.out.println("tttttttttttttttttttttt");
}
public Test(){
System.out.println("T constructed");
}
int i;
String s;
public void m1(int i){
this.i=i;
}
public String getS(){
return s;
}
}
老是报 java.lang.ClassNotFoundException
------解决思路----------------------
Class.forName() 这个方法是要写类的全限定名 也就是 包名.类名
你换成com.lshua.Test就OK了