I have been trying my hands with reflection today.. and bored with this error
What i am trying to acheive is , I have a class in which i get the name of other class using Class.forName("ReflectionTest") like this :
then i make an instance of this class by referring to Object class like this :
Object NewInst = Yogs.newInstance();
Then in the try section , I try to Locate a String field named hello using Field class , but when i run the code , it gives the above NoSuchFieldException , Can all of you experts highlight , where i am going wrong , below are the 2 java files which i have used for the above.
Please help in this new learning of mine. Thanks in advance.
Yogendra N Joshi
Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
The code works fine except for the fact that your class ReflectionTest does not compile as in the for loop you have not declared the variable i. After fixing the above problem, the program runs fine. Probably you have an earlier version of the class ReflectionTest that does not have the field Hello.