• 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Class.forName() method problem  RSS feed

 
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
 
Marshal
Posts: 60704
189
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!