aspose file tools
The moose likes Beginning Java and the fly likes Class.forName() method problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Class.forName() method problem" Watch "Class.forName() method problem" New topic
Author

Class.forName() method problem

yogesh kalaskar
Greenhorn

Joined: Jan 24, 2007
Posts: 6
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
Sheriff

Joined: Oct 13, 2005
Posts: 32599
    
    4
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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Class.forName() method problem
 
Similar Threads
generics
Generics-related question
Generics
Generics
Generics