File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error when calling a constructor" Watch "Error when calling a constructor" New topic

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
Ilja Preuss

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:

Tim Leung

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.
I agree. Here's the link:
subject: Error when calling a constructor
It's not a secret anymore!