问题
I'm running into a problem with a java app constantly throwing:
java.lang.NoClassDefFoundError: Could not initialize class java.net.ProxySelector.
I am running Suse Linux 10.3 and running java 1.6.0. My CLASSPATH is set to
/usr/lib/jvm/jre-1.6.0-openjdk/lib.
No other users seem to be having this error so I'm assuming its my setup. For those wondering the app is yamj (http://code.google.com/p/moviejukebox/)
Any ideas as to what maybe missing or what I maybe doing wrong?
Edit the full trace of the error is as follows:
java.lang.NoClassDefFoundError: Could not initialize class java.net.ProxySelector at sun.net.www.protocol.http.HttpURLConnection$5.run(HttpURLConnection.java:736) at java.security.AccessController.doPrivileged(Native Method) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:732) at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:672) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:997) at com.moviejukebox.thetvdb.tools.XMLHelper.getEventReader(XMLHelper.java:19) at com.moviejukebox.thetvdb.model.Mirrors.(Mirrors.java:30) at com.moviejukebox.thetvdb.TheTVDB.(TheTVDB.java:37) at com.moviejukebox.plugin.TheTvDBPlugin.(TheTvDBPlugin.java:57) at sun.reflect.GeneratedConstructorAccessor2.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:532) at java.lang.Class.newInstance0(Class.java:372) at java.lang.Class.newInstance(Class.java:325) at com.moviejukebox.plugin.DatabasePluginController.getMovieDatabasePlugin(DatabasePluginController.java:96) at com.moviejukebox.plugin.DatabasePluginController.access$000(DatabasePluginController.java:30) at com.moviejukebox.plugin.DatabasePluginController$1.initialValue(DatabasePluginController.java:44) at com.moviejukebox.plugin.DatabasePluginController$1.initialValue(DatabasePluginController.java:39) at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:160) at java.lang.ThreadLocal.get(ThreadLocal.java:150) at com.moviejukebox.plugin.DatabasePluginController.scan(DatabasePluginController.java:70) at com.moviejukebox.MovieJukebox.updateMovieData(MovieJukebox.java:1051) at com.moviejukebox.MovieJukebox.access$100(MovieJukebox.java:80) at com.moviejukebox.MovieJukebox$4.call(MovieJukebox.java:613) at com.moviejukebox.MovieJukebox$4.call(MovieJukebox.java:600) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java
回答1:
ProxySelector is an abstract class. Are you trying to instantiate it directly?
回答2:
My CLASSPATH is set to /usr/lib/jvm/jre-1.6.0-openjdk/lib.
don't think that should be in your CLASSPATH
try clearing the CLASSPATH and running it
回答3:
Firstly, you shouldn't have to put "/usr/lib/jvm/jre-1.6.0-openjdk/lib" on your classpath. The "java" command should put all of the standard J2SE libraries on the bootclasspath without you doing anything.
Second, it would help if you gave us the full stacktrace, not just the exception message. I suspect that the real problem is that java.net.ProxySelector (or something it depends on) is failing during static initialization. But only a stacktrace would confirm that.
回答4:
Since it's second result in google search on this error, I want to post this piece of code I found at some forum that helped me with the same exception. Cannot explain in details - it was just a quick test project for me, so I didn't have time for deeper investigation.
static {
try {
Class c = Class.forName("sun.net.spi.DefaultProxySelector");
if (c != null && ProxySelector.class.isAssignableFrom(c)) {
theProxySelector = (ProxySelector) c.newInstance();
}
} catch (Exception e) {
theProxySelector = null;
}
}
来源:https://stackoverflow.com/questions/1956789/java-lang-noclassdeffounderror-could-not-initialize-class-java-net-proxyselecto