日期:2014-05-20  浏览次数:20937 次

关于StackOverflowError问题
以下是在报错信息

Exception in thread "main" java.lang.StackOverflowError
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at sun.misc.Launcher$ExtClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
...
  (中间太多类似信息)
  ...
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sfa.a(sfa.java:38)
at twa.<clinit>(twa.java:98)
at kaa.a(kaa.java:50)
at ko.a(ko.java:211)
at kaa.<clinit>(kaa.java:120)
at ko.a(ko.java:211)
at oga.<clinit>(oga.java:66)
at ra.<clinit>(ra.java:583)
at ko.<clinit>(ko.java:223)
at kk.<clinit>(kk.java:82)
at hv.<clinit>(hv.java:419)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at Loder.<init>(Loder.java:70)
at Loder.main(Loder.java:225)



  以下是部分代码:

File clientj = new File("client.jar");
URLClassLoader cl = new URLClassLoader(new URL[]{clientj.toURI().toURL()
  });
 Class<?> clientc = cl.loadClass("client");
 Object clientobj = clientc.newInstance(); //报错部分显示是在创建实例中出错
 求大大帮忙看看!










------解决方案--------------------
构造函数不断自己初始化,形成了循环,不断的new,然后堆栈溢出了,建议换其他写法,这个不安全