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!

regards,

kanhakv

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) {
		super(title);
		//create menu bar and add it to frame.
		MenuBar mbar = new MenuBar();
		setMenuBar(mbar);
		// Create the menu items.
		Menu file = new Menu("File");
		MenuItem item1 = new MenuItem("New...");
		MenuItem item2, item3, item4, item5;
		file.add(item1);
		file.add(item2 = new MenuItem("Open..."));
		file.add(item3 = new MenuItem("Close"));
		file.add(item4 = new MenuItem("-"));
		file.add(item5 = new MenuItem("Quit..."));
		mbar.add(file);
		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("-"));
		mbar.add(edit);
		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"));
		edit.add(sub);
		// These are checkable menu items.
		debug = new CheckboxMenuItem("Debug");
		edit.add(debug);
		test = new CheckboxMenuItem("Testing");
		edit.add(test);

		// 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));
		item2.addActionListener(handler);
		item3.addActionListener(handler);
		item4.addActionListener(handler);
		item5.addActionListener(handler);
		item6.addActionListener(handler);
		item7.addActionListener(handler);
		item8.addActionListener(handler);
		item9.addActionListener(handler);
		item10.addActionListener(handler);
		item11.addActionListener(handler);
		item12.addActionListener(handler);
		debug.addItemListener(handler);
		test.addItemListener(handler);

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

}
	public void paint(Graphics g) {
		g.drawString(msg, 10, 200);
		if(debug.getState())
			g.drawString("Debug is on.", 10, 220);
		else
			g.drawString("Debug is off.", 10, 220);
		if(test.getState())
			g.drawString("Testing is on.", 10, 240);
		else
			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) {
		menuFrame.setVisible(true);
	}
}
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();
		if(arg.equals("New..."))
			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;
		menuFrame.repaint();
	}
	// Handle item events.
	public void itemStateChanged(ItemEvent ie) {
		menuFrame.repaint();
	}
}
// 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) {
				System.exit(0);
		  }
		});

				mf.setSize(380, 250);
			    mf.setVisible(true);
				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!

KanhaKv

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