• Post Reply Bookmark Topic Watch Topic
  • New Topic

Class Level Information  RSS feed

 
Kunder Akshay
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

I was just checking out on a program regarding Class level Information.



I tried the program in Eclipse and Netbeans but got ClassNotFoundException

Exception in thread "main" java.lang.ClassNotFoundException: Student
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at work.ClassInfo.main(ClassInfo.java:36)



I tried running the same program through Command Line and got

<b>Error: Could not find or load main class ClassInfo<b>

Just wondering what the issue here is .
 
Richard Hayward
Ranch Hand
Posts: 187
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the problem is with your use of the forName method:

public static Class<?> forName(String className) throws ClassNotFoundException

className has to be the fully qualified name of the desired class, in your case "work.Student"
 
Junilu Lacar
Sheriff
Posts: 11493
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need to do Class.forName(). Since you know which class you're interested in, just use the class literal:
 
Kunder Akshay
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Yes. I used the Fully Qualified name and it worked. Thank you so much.


Richard Hayward wrote:I think the problem is with your use of the forName method:

public static Class<?> forName(String className) throws ClassNotFoundException

className has to be the fully qualified name of the desired class, in your case "work.Student"
 
Kunder Akshay
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. I tried Class c = Student.class and it worked. Thank you so much.


Junilu Lacar wrote:You don't need to do Class.forName(). Since you know which class you're interested in, just use the class literal:
 
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!