public class ClassTest {
   public static void main(String[]arg)
   {

   String className="ClassTest";
   try
   {
   Class c=Class.forName(className);
   System.out.println(c); 
   }
   catch(Exception ex)
   {
   System.out.println("Hello");
   }
  
   }
}

解决方案 »

  1.   

    俺copy了你的代码,运行一点错误也没有.不过你捕获了异常后的处理方法嘛,嘿嘿.
      

  2.   

    是没有错误,为什么执行的是catch快的代码,就是说异常为什么抛出了?
      

  3.   

    你这个类是不是定义在某个包中了,如果是,需要用<package>.ClassTest才行.
      

  4.   

    Returns the Class object associated with the class or interface with the given string name. Invoking this method is equivalent to: 
      Class.forName(className, true, currentLoader)
     
    where currentLoader denotes the defining class loader of the current class. 
    For example, the following code fragment returns the runtime Class descriptor for the class named java.lang.Thread:    Class t = Class.forName("java.lang.Thread")
     
    A call to forName("X") causes the class named X to be initialized. 
    Parameters:
    className - the fully qualified name of the desired class. //注意这里
    Returns:
    the Class object for the class with the specified name.Class c=Class.forName(className);//className应包括包名称, 如果你的package是 my, 这里的className就应该是my.ClassTest