Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[newbie] IllegalAccessException

 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to create a new instance of a class within the package:



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

at homenetwork.bkr.training.ReflectionTest.main(ReflectionTest.java:27)

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

HelperClassesforClasses.java




Output:
java.lang.ClassNotFoundException: homenetwork.bkr.training
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 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)
at homenetwork.bkr.training.ReflectionTest.main(ReflectionTest.java:28)

 
Abhijeet Ravankar
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic