SprungLake9036
SprungLake9036

Reputation: 57

java error says JOptionPane cannot be resolved, didn't use JOptionPane

I'm kind of a beginner and I was using a tutorial to make a simple program that displays text fields on a JFrame. I didn't use a JLayeredPane in the whole project, but I still get this error that says, "The type javax.swing.JLayeredPane cannot be resolved. It is indirectly referenced from required .class files." Why do I get this error? Here's the code (there's two classes):

second class:

  package eventHandlerTutorial;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JOptionPane;
public class secondClass extends JFrame
{
private JTextField item1;
private JTextField item2;
private JTextField item3;
private JPasswordField passwordField;
public secondClass()
   {
    super("The title");
    setLayout(new FlowLayout());
    item1=new JTextField(10);
    add(item1);
    item2=new JTextField("enter text here");
    add(item2);
    item3=new JTextField("uneditable",20);
    item3.setEditable(false);
    add(item3);
    passwordField=new JPasswordField("mypass");
    add(passwordField);
    theHandler handler=new theHandler();
    item1.addActionListener(handler);
    item2.addActionListener(handler);
    item3.addActionListener(handler);
    passwordField.addActionListener(handler);
   }
private class theHandler implements ActionListener
        {
    public void actionPerformed(ActionEvent event)
            {
            String string="";
            if(event.getSource()==item1)
                string=String.format("field 1: %s",event.getActionCommand());
            else if(event.getSource()==item2)
                string=String.format("field 2: %s",event.getActionCommand());
            else if (event.getSource()==item3)
                string=String.format("field 3: %s",event.getActionCommand());
            else if(event.getSource()==passwordField)
                string=String.format("password field is: %s",event.getActionCommand());
            JOptionPane.showMessageDialog(null,string);         
            }
        }
}

main class:

 package eventHandlerTutorial;
import javax.swing.JFrame;
public class mainClass 
{
 public static void main(String[] args)
  {
  secondClass sc=new secondClass();
  sc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  sc.setSize(350,100);
  sc.setVisible(true);
  }
}

Upvotes: 1

Views: 8201

Answers (1)

sifr_dot_in
sifr_dot_in

Reputation: 3623

The error is explained:
"... cannot be resolved. It is indirectly referenced from required .class files.".

Another thing is, in your question you are saying "JOptionPane"
and
in explanation you are saying "JLayeredPane".

Sometimes (because of IDE errors) you are suppose to import manually.
Add

import javax.swing.JLayeredPane;

manually.
and check it out.

if, still you face issue, try to clean the project.

Upvotes: 0

Related Questions