• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help me in Java Reflection API  RSS feed

 
Akshay Sahu
Greenhorn
Posts: 26
Java Netbeans IDE
  • 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





 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
Java MS IE
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!