File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes ClassLoader returning null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "ClassLoader returning null" Watch "ClassLoader returning null" New topic

ClassLoader returning null

Mohammad Farhat
Ranch Hand

Joined: Nov 17, 2005
Posts: 51
i was having a problem lately with my applet being run inside the browser (i already mentioned that in a previous post entitled: NoClassDefFoundError) and i have tracked down the cause of that issue (thanks guys who helped in the last post) to being the classLoader returning null inside the browser environemnt, while returning a correct classLoader inside jbuilder.
The instruction i am using for returning a classLoader instance is the following:
Thread.currentThread().getContextClassLoader(); and it is returning null in the browser environment...whyyyyy?
Thanks guys,
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
I'm surprised it doesn't throw a SecurityException, which the javadocs say it should in the presence of a SecurityManager. Is this a signed applet, or have you altered any policy files? Applet aren't generally allowed to work with ClassLaoders; that's a feature of the sandbox they live in inside of a browser.
Mohammad Farhat
Ranch Hand

Joined: Nov 17, 2005
Posts: 51
Well, the issue is that i already signed the applet .. and still gives the same error
Isn't there a classloader for applets running inside a browser? and how come it works under jbuilder (the instruction would return to me as a classloader : sun.applet.AppletClassLoader inside jbuilder)
thanks a bunch..
Mohammad Farhat
Ranch Hand

Joined: Nov 17, 2005
Posts: 51
Okay guys,
here's the solution
the problem was that the classLoader is null, so what i did was add a single instruction that is initiating the thread "loader.setContextClassLoader(this.getClass().getClassLoader());"
this would set a classLoader to the thread and would remove all problems.
Thanks guys for the help
I agree. Here's the link:
subject: ClassLoader returning null
It's not a secret anymore!