aspose file tools*
The moose likes Beginning Java and the fly likes Method X not found in class Y error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Method X not found in class Y error" Watch "Method X not found in class Y error" New topic
Author

Method X not found in class Y error

Andrew Marshall
Greenhorn

Joined: Jul 09, 2003
Posts: 11
Howdy, howdy, howdy,
I've been doing Java since 5/21/03 when my intro class first met. When I open the class at the bottom of this posting in JBuilder, I get a "Method reusableMenuItemCreator not found in class BorderSamplerFrame at line 110".
What stupid little thing have I not learned yet?
BTW, if you type "this.", "reusableMenuItemCreator" appears as an available method! >8-(
Thanks,
Andrew
========================================
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
public class BorderSamplerFrame extends JFrame {
// ***Inner Classes***
private class InnerDestroyer extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
// DEBUGGING CODE
// JOptionPane.showMessageDialog(null, "I'm dying!");
System.exit(0);
}
}
private class MenuListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String aC = e.getActionCommand();
Color color = null;
int lineThickness = 1;
// DEBUGGING CODE
// JOptionPane.showMessageDialog(null, aC);
sampleLabel.setText(aC);
if (aC == "Raised Bevel Border")
sampleLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
else if (aC == "Lowered Bevel Border")
sampleLabel.setBorder(new BevelBorder(BevelBorder.LOWERED));
else if (aC == "Raised Etched Border")
sampleLabel.setBorder(new EtchedBorder(BevelBorder.RAISED));
else if (aC == "Lowered Etched Border")
sampleLabel.setBorder(new EtchedBorder(BevelBorder.LOWERED));
else if (aC.indexOf("Line Border") > -1)
{
// Extract the line color
if (aC.indexOf("Black") > -1)
color = Color.BLACK;
else if (aC.indexOf("Red") > -1)
color = Color.RED;
else if (aC.indexOf("Blue") > -1)
color = Color.BLUE;
// Extract the line thickness
if (aC.indexOf("Small") > -1)
lineThickness = 1;
else if (aC.indexOf("Medium") > -1)
lineThickness = 5;
else if (aC.indexOf("Large") > -1)
lineThickness = 10;
// Set the LineBorder properties
sampleLabel.setBorder(new LineBorder(color, lineThickness));
}
}
}
// ***Instance Variables***
JLabel sampleLabel;
MenuListener myMenuListener;
// ***Constructors***
public BorderSamplerFrame()
{
// Call parent default constructor
super();
// Set up the JFrame properties
this.setSize(400, 300);
this.addWindowListener(new InnerDestroyer());
this.setTitle("Enjoy sampling different borders!");
// Set up the JLabel
sampleLabel = new JLabel("Select a menu item to change this label.");
this.getContentPane().add(sampleLabel, BorderLayout.CENTER);
// Set up the menu bar
JMenuBar mainMenu = new JMenuBar();
this.setJMenuBar(mainMenu);
// Create the menu listener
myMenuListener = new MenuListener();
// Set up the "Borders" menu
JMenu bordersMenu = new JMenu("Borders");
mainMenu.add(bordersMenu);
// Set up the "Borders" submenus
JMenuItem bevelBorder, etchedBorder, lineBorder;
bevelBorder = new JMenu("Bevel Border");
bordersMenu.add(bevelBorder);
etchedBorder = new JMenu("Etched Border");
bordersMenu.add(etchedBorder);
lineBorder = new JMenu("Line Border");
bordersMenu.add(lineBorder);
// Set up the "Bevel Border" submenus
this.reusableMenuItemCreator("Raised", "Raised Bevel Border"
, myMenuListener, bevelBorder);
JMenuItem mI;
mI = new JMenuItem("Raised");
mI.setActionCommand("Raised Bevel Border");
mI.addActionListener(myMenuListener);
bevelBorder.add(mI);
mI = new JMenuItem("Lowered");
mI.setActionCommand("Lowered Bevel Border");
mI.addActionListener(myMenuListener);
bevelBorder.add(mI);
// Set up the "Etched Border" submenus
mI = new JMenuItem("Raised");
mI.setActionCommand("Raised Etched Border");
mI.addActionListener(myMenuListener);
etchedBorder.add(mI);
mI = new JMenuItem("Lowered");
mI.setActionCommand("Lowered Etched Border");
mI.addActionListener(myMenuListener);
etchedBorder.add(mI);
// Set up the "Line Border" submenus
JMenu m;
m = new JMenu("Small");
lineBorder.add(m);
{
// Set up the "Small" submenu
mI = new JMenuItem("Black");
mI.setActionCommand("Small Black Line Border");
mI.addActionListener(myMenuListener);
m.add(mI);
mI = new JMenuItem("Red");
mI.setActionCommand("Small Red Line Border");
mI.addActionListener(myMenuListener);
m.add(mI);
mI = new JMenuItem("Blue");
mI.setActionCommand("Small Blue Line Border");
mI.addActionListener(myMenuListener);
m.add(mI);
}
m = new JMenu("Medium");
lineBorder.add(m);
{
// Set up the "Medium" submenu
mI = new JMenuItem("Black");
mI.setActionCommand("Medium Black Line Border");
mI.addActionListener(myMenuListener);
m.add(mI);
mI = new JMenuItem("Red");
mI.setActionCommand("Medium Red Line Border");
mI.addActionListener(myMenuListener);
m.add(mI);
mI = new JMenuItem("Blue");
mI.setActionCommand("Medium Red Line Border");
mI.addActionListener(myMenuListener);
m.add(mI);
}
m = new JMenu("Large");
lineBorder.add(m);
{
// Set up the "Large" submenu
mI = new JMenuItem("Black");
mI.setActionCommand("Large Black Line Border");
mI.addActionListener(myMenuListener);
m.add(mI);
mI = new JMenuItem("Red");
mI.setActionCommand("Large Red Line Border");
mI.addActionListener(myMenuListener);
m.add(mI);
mI = new JMenuItem("Blue");
mI.setActionCommand("Large Blue Line Border");
mI.addActionListener(myMenuListener);
m.add(mI);
}
}
// ***Accessor Methods***
// ***Public Interface Behaviors***
// Method: getInputString()
// Input: N/A
// Output: N/A
// Process: Requests string from standard input and stores it in
// the searchString String object.
// ***Private Helper Behaviors***
// Method: readLine() ***Helper***
// Input: N/A
// Output: String containing a single input line from screen
// Process: Reads single word from standard input.
private void reusableMenuItemCreator(String name
, String actionCommand
, ActionListener actionListener
, JMenu parentMenu)
{
JMenuItem mI;
mI = new JMenuItem(name);
mI.setActionCommand(actionCommand);
mI.addActionListener(actionListener);
parentMenu.add(mI);
}
// ***Main/Driver Method***
public static void main(String[] args)
{
BorderSamplerFrame testGui = new BorderSamplerFrame();
testGui.setVisible(true);
}
}
Ta Ri Ki Sun
Ranch Hand

Joined: Mar 26, 2002
Posts: 442
the method signature is different, this line

is passing a JMenuItem as the 4th parameter, but you method expects a JMenu, so changing the call to will compile, I'm not sure if it will behave as expected, you'll have to look at that
have fun
Andrew Marshall
Greenhorn

Joined: Jul 09, 2003
Posts: 11
Another beginner lesson! When it says the method don't exist and it really do, CHECK THE COMPLETE SIGNATURE!!!
Of course, Java knew the signature was bad and could have been more helpful like you, Ta Ri Ki Sun.
Many thanks!
Andrew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Method X not found in class Y error
 
Similar Threads
JMenu
Run JApplet and no JMenuBar - Help!!
Class Communications
How to replace JTabbedPane's bevel border?
Swings