• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error when calling a constructor

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get an error when calling a constructor that makes a JMenu, just one menu with menu items, but it gives me an incompatible error when I call it
Here is the code

JMenu file = new StandardMenu();

what is wrong with it, the constructor is a public void, so it doesnt return anything. Im pulling my hair out at this one, so any help can be appreciated
Thanks
Jess
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Constructors don't have a return type - it should look like

public StandardMenu() {
...
}
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is your StandardMenu a subclass (directly or indirectlly) of JMenu?

For example:


Joyce
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JMenu objJMenu=new StandardMenu()

This declaration is only vaild
StandardMenu is a sub-class of JMenu
 
Jesse Walker
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my constructor doesnt have a return type. And if I change the StandardMenu to be a subclass of JMenu then the call should work, that makes sense I did the same thing with a frame but I subclass the class I made from JFrame, I feel stupid now but thanks for your help.
Jess
reply
    Bookmark Topic Watch Topic
  • New Topic