Question:
System.out.println(""); out cannot be resolved error?
Chris
2011-12-10 19:49:51 UTC
I'm having an error with a small GUI I'm writing for a project. It's probably a stupid mistake on my half but I just can't work it out (it's 3:47am :( ). My code is:

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class LoginGUI extends JFrame implements ActionListener {

JTextField username = new JTextField(15);
JPasswordField password = new JPasswordField(15);
JButton submit = new JButton("Submit");
JButton cancel = new JButton("Cancel");

public LoginGUI(){
super("Login to the Project Management System");
setBounds(150,200,200,175);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel pane = new JPanel();
JLabel userLabel = new JLabel("Username: ");
JLabel passLabel = new JLabel("Password: ");
pane.add(userLabel);
pane.add(username);
pane.add(passLabel);
pane.add(password);
pane.add(submit);
submit.addActionListener(this);
pane.add(cancel);
cancel.addActionListener(this);
add(pane);
setVisible(true);

}

public void actionPerformed(ActionEvent evt) {
Object source = evt.getSource();
if(source == submit){
System.out.println("submit hit");
}else if(source == cancel){
setVisible(false);
}

}

public static void main(String[] args) {
LoginGUI login = new LoginGUI();
}
}

And my compile error is:

Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
out cannot be resolved or is not a field

at LoginGUI.actionPerformed(LoginGUI.java:45)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Thanks!
Four answers:
Bill R
2011-12-10 20:35:18 UTC
I would suggest trying java.lang.System.out instead. Chances are you have another class or interface named System.
patin
2016-10-18 01:47:35 UTC
Main Cannot Be Resolved Or Is Not A Field
Silent
2011-12-10 20:07:23 UTC
Well, that's...really weird.



This compiles fine for me; are you using some really weird non-standard JVM or something? Are you maybe running this against a different version of the JVM than you compiled it against?



Are you compiling this from the command line or in some IDE?
lovelyguy
2011-12-10 19:53:26 UTC
submit what you have written


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...