A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© hollywood2014 中级黑马   /  2014-10-22 19:18  /  865 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  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错误,还请大神支招!
复制代码

评分

参与人数 1黑马币 +1 收起 理由
杨佳名 + 1

查看全部评分

2 个回复

倒序浏览
dreamseekerkun 来自手机 中级黑马 2014-10-23 01:25:36
沙发
包名写全要
回复 使用道具 举报
在前面加上包名
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马