hello all members!

i have just written a java application about menu. i got error that: cannot find symbol. could you all tell me all possible causes of this problem. i have tried to follow some of instructions on internet, but no help. thank in advance for your help.

p.s: i am just Java beginner!



Edited 5 Years Ago by kanhakv: wrong grammar

You are using something that is not declared or doesn't exists or is not visible from where you are trying to use it

Dear Helper:

Thank you so much for you intention. Tell you, this is my homework. I have been struggle one whole day already, but no result. Here is the error:

D:\Asia Euro University\Java Programming\@School\MenuDemo.java:141: cannot find symbol
symbol : constructor MenuFrame()
location: class MenuFrame
mf = new MenuFrame();
1 error

Tool completed with exit code 1

+++Here is the code:

import java.awt.*;
import java.awt.event.*;

// Create a subclass of Frame.
class MenuFrame extends Frame {

	String msg ="";
	CheckboxMenuItem debug, test;
	MenuFrame(String title) {
		//create menu bar and add it to frame.
		MenuBar mbar = new MenuBar();
		// Create the menu items.
		Menu file = new Menu("File");
		MenuItem item1 = new MenuItem("New...");
		MenuItem item2, item3, item4, item5;
		file.add(item2 = new MenuItem("Open..."));
		file.add(item3 = new MenuItem("Close"));
		file.add(item4 = new MenuItem("-"));
		file.add(item5 = new MenuItem("Quit..."));
		Menu edit = new Menu("Edit");
		MenuItem item6, item7, item8, item9;
		edit.add(item6 = new MenuItem("Cut"));
		edit.add(item7 = new MenuItem("Copy"));
		edit.add(item8 = new MenuItem("Paste"));
		edit.add(item9 = new MenuItem("-"));
		Menu sub = new Menu("Special");
		MenuItem item10, item11, item12;
		sub.add(item10 = new MenuItem("First"));
		sub.add(item11 = new MenuItem("Second"));
		sub.add(item12 = new MenuItem("Third"));
		// These are checkable menu items.
		debug = new CheckboxMenuItem("Debug");
		test = new CheckboxMenuItem("Testing");

		// Create an object to handle action and item events.
		MyMenuHandler handler = new MyMenuHandler(this);
		// Register it to receive those events.
		item1.addActionListener(new MyMenuHandler(this));

		// Create an object to handle window events.
		MyWindowAdapter adapter = new MyWindowAdapter(this);
		// Register it to receive those events.

	public void paint(Graphics g) {
		g.drawString(msg, 10, 200);
			g.drawString("Debug is on.", 10, 220);
			g.drawString("Debug is off.", 10, 220);
			g.drawString("Testing is on.", 10, 240);
			g.drawString("Testing is off.", 10, 240);
class MyWindowAdapter extends WindowAdapter {
	MenuFrame menuFrame;
	public MyWindowAdapter(MenuFrame menuFrame) {
		this.menuFrame = menuFrame;
	public void windowClosing(WindowEvent we) {
class MyMenuHandler implements ActionListener, ItemListener {
	MenuFrame menuFrame;
	public MyMenuHandler(MenuFrame menuFrame) {
		this.menuFrame = menuFrame;
	// Handle action events.
	public void actionPerformed(ActionEvent ae) {
		String msg = "You selected : ";
		String arg = (String)ae.getActionCommand();
			msg += "New.";
		else if(arg.equals("Open..."))
			msg += "Open.";
		else if(arg.equals("Close"))
			msg += "Close.";
		else if(arg.equals("Quit..."))
			msg += "Quit.";
		else if(arg.equals("Edit"))
			msg += "Edit.";
		else if(arg.equals("Cut"))
			msg += "Cut.";
		else if(arg.equals("Copy"))
			msg += "Copy.";
		else if(arg.equals("Paste"))
			msg += "Paste.";
		else if(arg.equals("First"))
			msg += "First.";
		else if(arg.equals("Second"))
			msg += "Second.";
		else if(arg.equals("Third"))
			msg += "Third.";
		else if(arg.equals("Debug"))
			msg += "Debug.";
		else if(arg.equals("Testing"))
			msg += "Testing.";
		menuFrame.msg = msg;
	// Handle item events.
	public void itemStateChanged(ItemEvent ie) {
// Create frame window.
public class MenuDemo extends Frame {
	static MenuDemo md;
	static MenuFrame mf;

	public static void main (String[] args) {

		md = new MenuDemo();

	    mf = new MenuFrame();
		//set setting for mf
		md.setSize (380, 250);
		md.setVisible (true);
		md.setTitle ("Parents Window na");
		md.setLocationRelativeTo (null);
		md.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent w) {

				mf.setSize(380, 250);
				mf.setTitle ("Child Window na");
				mf.setLocationRelativeTo (null);



Edited 5 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

Read the error messages that you get. They tell you exactly what the problem is:
cannot find symbol
symbol : constructor MenuFrame()

There isn't a constructor MenuFrame() . You haven't declared such constructor.
Constructors are like methods. When you call them you need to pass the arguments, that they were declared to have.

Dear JavaAddict:

Thank so much for your valuable time spending to help me. I will take this into account. Let give me some times. I will try to take a look at the code again.

Thank You!

maybe you've seen code snippets in which it works.

the constructor without any arguments, is the default constructor. If you don't declare any constructors at all, the compiler will 'create' the default constructor for you, since you'll need to have a way to instantiate the class.

in the code above, on the other hand, you've provided a constructor that takes a String object as an argument. whenever you provide an overloaded constructor, the compiler will not automatically generate the default constructor, which is why in this case, as JavaAddict pointed out, it won't work, since the constructor you're calling does not exist.

Dear stultuske:

Thank so much for your help. You're just like my teacher. I am correcting it. Hope it will get result. I will let you know after I've done it! Thank :)

Good Luck!


This article has been dead for over six months. Start a new discussion instead.