• Post Reply Bookmark Topic Watch Topic
  • New Topic

Another way of initializing an object  RSS feed

 
Vinoth Kumar Kannan
Ranch Hand
Posts: 276
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Class.forName().newInstance() is another way of initializing an object,right?
Is there a problem with my code? I thought it should work fine, but i'm just getting - java.lang.ClassNotFoundException. Both of the classes are in the same package!
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried the fully-qualified name of the class?
 
Ram Narayan.M
Ranch Hand
Posts: 247
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your prgm is working fine... Please run the prgm with this command

 
sharma pankaj
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinoth Kumar Kannan wrote:
Class.forName().newInstance() is another way of initializing an object,right?
Is there a problem with my code? I thought it should work fine, but i'm just getting - java.lang.ClassNotFoundException. Both of the classes are in the same package!


Good
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please avoid abbreviations like prgm, Ram Narayan.M
 
Vinoth Kumar Kannan
Ranch Hand
Posts: 276
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Have you tried the fully-qualified name of the class?

Oh, yes...I seemed to have missed that!!

works perfect!
Thank you Campbell!

and Ram,i tried what you suggested. It isnt helping. I get this,

I just use

for running my code.
Is 'java -cp' supposed to do anything special or different?!
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinoth Kumar Kannan wrote:
Is 'java -cp' supposed to do anything special or different?!



java -cp vin_java ErrorCheck


it is supposed to add a classpath to vin_java
and then run the class file "ErrorCheck" using that path.....
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think if
java vin_java.ErrorCheck
works, then it is unnecessary to add the package to your classpath. Surely it should be
java -cp vin_java vin_java.ErrorCheck
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!