• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Help me in Java Reflection API

 
Greenhorn
Posts: 26
Netbeans IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a new guy to Dependency injection and I have tried something different. Can anyone please help me out...!!!

I have a web application with following requirements:

1. People will write the name of the class in an xml file.
2. They will also write their variable name in the same xml, for which you have to load a string value.

I have done something like this:

1. I have written a startup servlet, where I am loading the xml file location as a stream.
2. Using DOM, I am parsing the xml file and fetching all the required data.
3. In my dependency injection class, I am first loading the class as follows:

Class actualClass = Class.forName(classValueInXML):
Object actualObject = actualClass.newInstance();
Field acutalField = actualClass.getDeclaredField("Stranger");
actualField.set(actualObject, "I am an stranger");


4. The above code is running absolutely fine.
5. Now when I am trying to execute the same file by calling it from some other place, then it says, Stranger not initialized. NullPointerException.

I am new to this. Please anyone, help me !!!

Thanks in Advance !!!

Akshay Sahu





 
Ranch Hand
Posts: 312
MS IE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe, your XML file could not be found in the path where your executable is present.
 
I have always wanted to have a neighbor just like you - Fred Rogers. Tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!