• 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
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

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: 63447
206
  • 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
 
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!