Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Class.forName() method problem  RSS feed

 
yogesh kalaskar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package test_package;

import java.lang.reflect.*;

public class RunAnnotation
{
public static void main(String[] args) throws Exception
{
for (Method m : Class.forName("Generics").getMethods())
{
System.out.println(m.getName());
}
}
}
///////////////////////////////////////////////////////

This is small program ,wherein i am passing argument to Class.forname("nameOfClass").Both classes are in same package .but getting error like..

Exception in thread "main" java.lang.ClassNotFoundException: Generics

Thanks in Advance

Yogesh g k
 
Campbell Ritchie
Marshal
Posts: 55751
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

I got it to work by the simple technique of using the fully qualified name of the class. Try "test_package.Generics" as the class name.

And why are you calling it "RunAnnotation" when it doesn't seem to do anything with annotations?

CR
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!