aspose file tools*
The moose likes Beginning Java and the fly likes Error when calling a constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error when calling a constructor" Watch "Error when calling a constructor" New topic
Author

Error when calling a constructor

Jesse Walker
Ranch Hand

Joined: Aug 18, 2004
Posts: 50
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
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Constructors don't have a return type - it should look like

public StandardMenu() {
...
}


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
Is your StandardMenu a subclass (directly or indirectlly) of JMenu?

For example:


Joyce
Tim Leung
Greenhorn

Joined: Sep 05, 2004
Posts: 8
JMenu objJMenu=new StandardMenu()

This declaration is only vaild
StandardMenu is a sub-class of JMenu
Jesse Walker
Ranch Hand

Joined: Aug 18, 2004
Posts: 50
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error when calling a constructor
 
Similar Threads
Creating one class from another
JToolBar in applet
JMenu Focus
How to add JMenuItem to my JMenu??
JPopupMenu or JMenu - neither is quite what I'm after.