• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Same doubt again regarding constructors

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




I am facing the following error when i try to compile the above code please reply me with the correct solution:


java.lang.NoSuchMethodError: main
Exception in thread "main"
 
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I can see you followed my advice with the "Code" tag
However, I answered your question in your first post

Please check your first post.

Regards,
Alex
 
Narayana.Vaddi
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I complied the piece of code editted by you but still i'm facing the same error!!
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Naranaya,

Welcome to Javaranch! First of all, you will need to check out the Javaranch policies regarding names.

You're missing a close parenthesis. Here's your correct code:



You need to name your source code Test2.java because your Test2 class is coderanch. Now, I compiled it and it returned:
cannot find symbol
symbol: constructor Sup()
location: class Sup

It's because in your Sup class, you declared a constructor with argument, so effectively, Java will no longer insert a default constructor (a constructor without argument) in your Sup class. Now, when you're compiling Test2.java, there is an implicit call to super under your Test2 Constructor:



And this is looking for a constructor under Sup with no arguments in it, which you don't have.

Here's the correction:
 
Narayana.Vaddi
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for again disturbing you but,still i am facing the forllowing error:


Exception in thread "main" java.lang.Error: Unresolved compilation problem:

at Test2.main(Test1.java:12)
 
Narayana.Vaddi
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya i identified my problem now,i created another class Test1 and extended Test2,while i am trying to run the Test2 class,the Test 1 is effected,and the changes what i did is didn't get reflected in Test2,now when i deleted the Test1 i can able to run Test2 class and i got the out put,


Thanks once again.
 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Test1.java !!!

Your file should be "Test2.java", the same as your public class.

Regards,
Alex
 
Narayana.Vaddi
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Before creating the Test2.java class i ran another piece of code which is no where related to our conversation. These two are different, but as a regular mistake i used the same name in both of the examples...and i faced that problem.Now it got resolved.

Thanks.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Narayana",
Please check your private messages.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic