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

[newbie] IllegalAccessException

Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 664

I am trying to create a new instance of a class within the package:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Unhandled exception type ClassNotFoundException
Unhandled exception type InstantiationException
Unhandled exception type IllegalAccessException


I also tried to use it within another function (where actually I want it):

at$ Source)
at Method)
at 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.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)

Abhijeet Ravankar
Ranch Hand

Joined: Mar 15, 2009
Posts: 62
class.forName() throws ClassNotFoundException and public newInstance() throws InstantiationException and IllegalAccessException. So, I hope your entire code is in try-catch block.

I also had problems sometimes with Class.forName(String) function. Instead of that, try to use the other variant:

public static Class<?> forName(String name,boolean initialize,ClassLoader loader) throws ClassNotFoundException

Hope it helps.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46397
Afraid your suggestion of Class#forName in the catch won't work, because you are throwing an un-handled checked Exception.

I recommend a trip to the Java™ Tutorials.
I agree. Here's the link:
subject: [newbie] IllegalAccessException
It's not a secret anymore!