Results 1 to 7 of 7
Thread: Reflection
- 04-21-2011, 05:51 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 6
- Rep Power
- 0
Reflection
I hav written a simple code for finding out all the data fields of a class but i am getting an exceptio :"NoClassFoundException".....I am not understanding hoe to remove it...I would glad to receive any one's help....
import java.lang.reflect.*;
class SampleField
{ public static void getField(Class c)
{ //Class c= Class.forName(s);
Field f[]=c.getFields();
for(int i=0;i<f.length;i++)
{ System.out.println(" ");
Class type=f[i].getType();
System.out.print(type.getName());
System.out.print(""+f[i].getName());
}
}
public static void main(String... s1)
{ try{
Class c= Class.forName(s1[0]);
getField(c);
}catch(Exception e){System.out.println(e);}
}
}
- 04-21-2011, 06:06 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Add the class that was not found to the classpath when you run the program.
- 04-21-2011, 06:06 AM #3
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
- 04-21-2011, 06:11 AM #4
Member
- Join Date
- Apr 2011
- Posts
- 6
- Rep Power
- 0
import java.lang.reflect.*;
import java.awt.*;
class SampleField
{ public static void getField(Class c)
{ //Class c= Class.forName(s);
Field f[]=c.getFields();
for(int i=0;i<f.length;i++)
{ System.out.println(" ");
Class type=f[i].getType();
System.out.print(type.getName());
System.out.print(""+f[i].getName());
}
}
public static void main(String... s1)
{ try{
Class c= Class.forName(s1[0]);
getField(c);
}catch(Exception e){System.out.println(e);}
}
}
I am sending a class name java.lang.thread through command line argument but still it is showing the same exception....:(
- 04-21-2011, 06:28 AM #5
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Did you use the right case, Thread instead of thread?
- 04-21-2011, 06:32 AM #6
Member
- Join Date
- Apr 2011
- Posts
- 6
- Rep Power
- 0
- 05-04-2011, 08:02 AM #7
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
The above may just be the funniest spammer ever.
Similar Threads
-
reflection
By rfabbri in forum Advanced JavaReplies: 3Last Post: 12-07-2010, 08:55 AM -
Generics and reflection
By juza in forum Advanced JavaReplies: 1Last Post: 11-30-2010, 03:48 PM -
how to use reflection
By sunilpatel28 in forum Advanced JavaReplies: 1Last Post: 12-10-2008, 10:51 PM -
Array Reflection: Multi Array Reflection
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:08 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks