wood burning stoves
The moose likes Beginning Java and the fly likes Error messages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error messages" Watch "Error messages" New topic

Error messages

Rose Evans
Ranch Hand

Joined: Oct 14, 2004
Posts: 195
Why do I get these errors? Im so lost...

F:\Java II\MenuReporter\RoseSarah\MenuSwing2.java:14: 'class' or 'interface' expected
private JTextField message;
F:\Java II\MenuReporter\RoseSarah\MenuSwing2.java:137: cannot resolve symbol
symbol : variable message
location: class MenuSwing2
message = new JTextField(30);
F:\Java II\MenuReporter\RoseSarah\MenuSwing2.java:138: cannot resolve symbol
symbol : variable message
location: class MenuSwing2
content.add(message, BorderLayout.CENTER);
F:\Java II\MenuReporter\RoseSarah\MenuSwing2.java:138: cannot resolve symbol
symbol : variable content
location: class MenuSwing2
content.add(message, BorderLayout.CENTER);
F:\Java II\MenuReporter\RoseSarah\MenuSwing2.java:145: cannot resolve symbol
symbol : variable message
location: class MenuSwing2
5 errors

Tool completed with exit code 1


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

private JTextField message;

public class MenuSwing2 extends JFrame implements ActionListener

//declare variables for components we will need
private JPanel foodPanel;
private JButton food1;
private JButton food2;
private JButton food3;
private JButton food4;
private JButton food5;
private JButton food6;
private JButton food7;
private JButton food8;

private JPanel rankPanel;
private JButton rankBtn5;
private JButton rankBtn4;
private JButton rankBtn3;
private JButton rankBtn2;
private JButton rankBtn1;

private JPanel outputPanel;
private JLabel banner;
private JLabel enterEntree;
private JTextField entreeNum;

//variables to hold food names (until file input in phased in)
private String s1="Classic Nachos";
private String s2="Fajitas";
private String s3="Cajun Chicken";
private String s4="Cheeseburger Deluxe";
private String s5="Tuna Steak";
private String s6="Ribeye Steak";
private String s7="Baby Back Ribs";
private String s8="Fried Chicken";

public MenuSwing2() // constructor

setSize (WIDTH, HEIGHT);
addWindowListener(new WindowDestroyer());
Container contentPane = getContentPane();
JPanel buttonPanel = new JPanel();
JPanel buttonPanel1 = new JPanel();

buttonPanel.setLayout(new GridLayout(2,8));
buttonPanel1.setLayout(new GridLayout(1,5));

JButton food1 = new JButton ("Classic Nachos");
food1.setBackground (Color.RED);

JButton food2 = new JButton ("Fajitas");
food2.setBackground (Color.RED);

JButton food3 = new JButton ("Cajun Chicken");
food3.setBackground (Color.RED);

JButton food4 = new JButton ("Cheeseburger Deluxe");
food4.setBackground (Color.RED);

JButton food5 = new JButton ("Tuna Steak");
food5.setBackground (Color.RED);

JButton food6 = new JButton ("Ribeye Steak");
food6.setBackground (Color.RED);

JButton food7 = new JButton ("Babyback Ribs");
food7.setBackground (Color.RED);

JButton food8 = new JButton ("Fried Chicken");
food8.setBackground (Color.RED);

JButton rankBtn1 = new JButton ("Excellent");
rankBtn1.setBackground (Color.RED);

JButton rankBtn2 = new JButton ("Very Good");
rankBtn2.setBackground (Color.RED);

JButton rankBtn3 = new JButton ("Average");
rankBtn3.setBackground (Color.RED);

JButton rankBtn4 = new JButton ("Fair");
rankBtn4.setBackground (Color.RED);

JButton rankBtn5 = new JButton ("Poor");
rankBtn5.setBackground (Color.RED);

contentPane.add(buttonPanel, BorderLayout.NORTH );
contentPane.add(buttonPanel1, BorderLayout.SOUTH);

message = new JTextField(30);
content.add(message, BorderLayout.CENTER);

// refer to the "Steps for Advanced Swing programs
public void actionPerformed(ActionEvent e)
if (e.getActionCommand().equals("Classic Nachos"))

// stub
// do not complete this method yet
public static void main(String[] args)
// inFile is named MenuList.txt
// open File
// read in data for each menu item

MenuSwing2 chilis = new MenuSwing2(); //instantiate a GUI Object
chilis.setTitle("Menu Grader!");


) ) ) )
Henrik Engert
Ranch Hand

Joined: Apr 26, 2005
Posts: 70
private JTextField message;

needs to be declared inside the class.

Like this:

[ May 03, 2005: Message edited by: Henrik Engert ]

Hentay Duke
Ranch Hand

Joined: Oct 27, 2004
Posts: 198
First three things in a class must be
1.) package statement (if applicable)
2.) import statements (if needed)
3.) class declaration

The first error should have clued you in. It says it's expecting a class or interface, yet you declared a variable. The error messages can often tell you quite a bit, get used to reading them.
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

the first error message has a line:

F:\Java II\MenuReporter\RoseSarah\MenuSwing2.java:14: 'class' or 'interface' expected

this is telling you to look at line 14 in the MenuSwing2.java file. this is about where the problem is (often it's on this line, sometimes, just above).

so, look at line 14... the error message tells you that you are doing something it's not expecting - it wants either the word 'class' or 'interface' to be there, and it didn't see it. why?

because you're declaring a variable there. In Java, variables can't really live outside of a class. so perhaps we should move it to inside the class itself.

when you get a long list of errors like this, fix the first one first, then recompile. if you fixt this first one, many if not all of the others should dissappear. although others might now pop up.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Rose Evans
Ranch Hand

Joined: Oct 14, 2004
Posts: 195
Thank you so much for your help!!!
I agree. Here's the link: http://aspose.com/file-tools
subject: Error messages
It's not a secret anymore!