0

Hi. I am trying to write a function that when given a class, will tell you the number of methods that class has. I am getting the java.lang.noclassfoundexception message. I read something about adding to the PATH but was unsure. I also tried using HelloWorld.class, but that did not work either. Any help would be much apreciated. Below is my code:

String test = "HelloWorld.java";
Class cls = Class.forName(test); 
int Mcount = cls.getDeclaredMethods().length;
System.out.println("Mcount = " + Mcount);
3
Contributors
3
Replies
4
Views
4 Years
Discussion Span
Last Post by corby
0

Do some reading on reflection - the means by which you can use RTTI (runtime type identification) methods to do what you want. Google is your friend...

0

tHelloWorld.java is the name of a source file, not a class. Assuming you have compiled HelloWorld, and the .class file is somewhere in your classpath, all you need to do is o change line 1 so the string just contains the class name.

0

hey i figured it out. It was the location of my file. I put in the correct path to the location. I was doing the path wrong originally. Anyways thanks for the help!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.