黑马程序员技术交流社区

标题: 反射ClassNotFound [打印本页]

作者: hollywood2014    时间: 2014-10-22 19:18
标题: 反射ClassNotFound
  1. public class Reflection_test {
  2.         public static void main(String[] args) {
  3.                 // TODO Auto-generated method stub
  4.                 Scanner input=new Scanner(System.in);
  5.                 //String line=input.nextLine();       
  6.                 try {
  7.                         Class c=Class.forName("test");
  8.                         test t2=(test)c.newInstance();
  9.                         t2.show();
  10.                 } catch (Exception e) {
  11.                         // TODO: handle exception
  12.                 }
  13.         }
  14. }
  15. class test{
  16.         public test(){}
  17.         public void show()
  18.         {
  19.                 System.out.println("hi, i am A");
  20.         }
  21. }这段代码为什么会出现ClassNotFound错误,还请大神支招!
复制代码


作者: dreamseekerkun    时间: 2014-10-23 01:25
包名写全要
作者: zhappy    时间: 2014-10-23 08:32
在前面加上包名




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2