Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Help me in Java Reflection API

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.
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic