用Class.forName()加载类
class Cls { private Cls() { } /** N o w J a v a . c o m - 时 代 Java **/ } public class ClassTrouble { public static void main(String... args) { try { Class<?> c = Class.forName("Cls"); c.newInstance(); // InstantiationException // production code should handle these exceptions more gracefully } catch (InstantiationException x) { x.printStackTrace(); } catch (IllegalAccessException x) { /*来自 N o w J a v a . c o m - 时 代 Java*/ x.printStackTrace(); } catch (ClassNotFoundException x) { x.printStackTrace(); } } }