• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Executing Singleton class with Custom Class Loaders

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am trying to develop a custom class loader to load a singleton class.

Below are the code snippets involved.

I compiled Singleton1.java and got the class file in the same folder.

When i am trying to run ChkSingletonCL.java, i am getting a java.lang.IllegalAccessException
@ line 45. How can I run the Singleton class with custom class loader.

The Error msg. is "java.lang.IllegalAccessException: Class sripy.classLoader.ChkSingletonCL can not access a member of class Singleton1 with modifiers "private"

Basically i want to test the Singleton behaviours in the custom class loaders.

Singleton1.java




ChkSingletonCL.java





regards
sri
 
Marshal
Posts: 77275
371
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question too difficult for "beginning". Moving thread.
 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

first, your Singleton1 class doesn't have a getName() method, so you must declare it first before invoking it from the main().


Second, constructor Singleton() is private, therefore you cannot use Class.newInstance() method because it works only for public default constructor.
Third, method getName() is private, so you cannot use class.getMethod(name,...) method because it works only for public methods.
See javadoc for details.

Try this code:
 
sriram sundararajan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ireneusz,
Thanks i can now able to call the singleton class. I think its high time for me to tune up my reflection knowledge. Thanks again.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic