Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compilation error

 
joshua antony
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I get a compilation error stating
cannot reference x before supertype constructor has been called..
Do i get this error just because it is specified in the JLS that instance variables cannot be referenced in constructor before call to super?

I am not able to understand this, because any way x is initialised to 5 before we make a call to super constructor.
Am I missing something silly..
Regards,
Joshua
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The superclass will be initialized before the subclass. If x were to be resolved to 5 and sent to the constructor of the superclass, then the subclass would have to be initialized before the superclass.
 
Swapnil Trivedi
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Keith........It was a real brainer problem
Now it's compiling but giving runtime exception
"NoClassDefFoundError"...May be I am wrong somewhere..Can u pls help.


Regards
Swapnil
[ June 21, 2006: Message edited by: Swapnil Trivedi ]
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you talking about the code from Joshua?

Can you post the changes you made to it?

It sounds like you had a problem with either the command line or CLASSPATH.
[ June 21, 2006: Message edited by: Keith Lynn ]
 
Swapnil Trivedi
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Keith,
I am sorry for my last post actually yesterday I downloaded the enthuware database so for that I made some changes in my classpath and I forgot to include the current directory in it. So, that's why it was giving error...Sorry for your inconvenience

Everything is working fine now...including Joshua's code

again thanks's alot for your help...


regards
Swapnil

[ June 21, 2006: Message edited by: Swapnil Trivedi ]
[ June 21, 2006: Message edited by: Swapnil Trivedi ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic