Error in Java with Exception in thread "main" java.lang.RuntimeException [duplicated]

1

I have the code

import java.awt.*;

import java.awt.event.*;


import javax.swing.*;


//Esta clase muestra un cuadro de diálogo para introducir Servidor.

public class ConnectDialog extends JDialog {

// Estos son los tipos de servidor de correo electrónico.
private static final String[] TYPES = {"pop3", "imap"};

// Cuadro combinado para tipos de servidor de correo electrónico.
private JComboBox typeComboBox;

// Servidor, nombre de usuario y campos de texto del servidor SMTP.
private JTextField serverTextField, usernameTextField;
private JTextField smtpServerTextField;

// Campo de texto de contraseña.
private JPasswordField passwordField;

// Constructor para el diálogo.
public ConnectDialog(Frame parent) {
    // Llame a super constructor, especificando que el diálogo es modal.
    super(parent, true);

    // Establecer el título del diálogo.
    setTitle("Connect");

    // Manejar eventos de cierre.
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            actionCancel();
        }
    });

    // Configuración del panel de configuración.
    JPanel settingsPanel = new JPanel();
    settingsPanel.setBorder(
            BorderFactory.createTitledBorder("Connection Settings"));
    GridBagConstraints constraints;
    GridBagLayout layout = new GridBagLayout();
    settingsPanel.setLayout(layout);
    JLabel typeLabel = new JLabel("Type:");
    constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.EAST;
    constraints.insets = new Insets(5, 5, 0, 0);
    layout.setConstraints(typeLabel, constraints);
    settingsPanel.add(typeLabel);
    typeComboBox = new JComboBox(TYPES);
    constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.WEST;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    constraints.insets = new Insets(5, 5, 0, 5);
    constraints.weightx = 1.0D;
    layout.setConstraints(typeComboBox, constraints);
    settingsPanel.add(typeComboBox);
    JLabel serverLabel = new JLabel("Server:");
    constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.EAST;
    constraints.insets = new Insets(5, 5, 0, 0);
    layout.setConstraints(serverLabel, constraints);
    settingsPanel.add(serverLabel);
    serverTextField = new JTextField(25);
    constraints = new GridBagConstraints();
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    constraints.insets = new Insets(5, 5, 0, 5);
    constraints.weightx = 1.0D;
    layout.setConstraints(serverTextField, constraints);
    settingsPanel.add(serverTextField);
    JLabel usernameLabel = new JLabel("Username:");
    constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.EAST;
    constraints.insets = new Insets(5, 5, 0, 0);
    layout.setConstraints(usernameLabel, constraints);
    settingsPanel.add(usernameLabel);
    usernameTextField = new JTextField();
    constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    constraints.insets = new Insets(5, 5, 0, 5);
    constraints.weightx = 1.0D;
    layout.setConstraints(usernameTextField, constraints);
    settingsPanel.add(usernameTextField);
    JLabel passwordLabel = new JLabel("Password:");
    constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.EAST;
    constraints.insets = new Insets(5, 5, 5, 0);
    layout.setConstraints(passwordLabel, constraints);
    settingsPanel.add(passwordLabel);
    passwordField = new JPasswordField();
    constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    constraints.insets = new Insets(5, 5, 5, 5);
    constraints.weightx = 1.0D;
    layout.setConstraints(passwordField, constraints);
    settingsPanel.add(passwordField);
    JLabel smtpServerLabel = new JLabel("SMTP Server:");
    constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.EAST;
    constraints.insets = new Insets(5, 5, 5, 0);
    layout.setConstraints(smtpServerLabel, constraints);
    settingsPanel.add(smtpServerLabel);
    smtpServerTextField = new JTextField(25);
    constraints = new GridBagConstraints();
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    constraints.insets = new Insets(5, 5, 5, 5);
    constraints.weightx = 1.0D;
    layout.setConstraints(smtpServerTextField, constraints);
    settingsPanel.add(smtpServerTextField);

    // Configuración del panel de botones.
    JPanel buttonsPanel = new JPanel();
    JButton connectButton = new JButton("Connect");
    connectButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            actionConnect();
        }
    });
    buttonsPanel.add(connectButton);
    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            actionCancel();
        }
    });
    buttonsPanel.add(cancelButton);

    // Añadir paneles para mostrar.
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(settingsPanel, BorderLayout.CENTER);
    getContentPane().add(buttonsPanel, BorderLayout.SOUTH);

    // Diálogo de tamaño a los componentes.
    pack();

    // Centro de diálogo sobre la aplicación.
    setLocationRelativeTo(parent);
}

// Validar la configuración de la conexión y cerrar el cuadro de diálogo.
private void actionConnect() {
    if (serverTextField.getText().trim().length() < 1
            || usernameTextField.getText().trim().length() < 1
            || passwordField.getPassword().length < 1
            || smtpServerTextField.getText().trim().length() < 1) {
        JOptionPane.showMessageDialog(this,
                "One or more settings is missing.",
                "Missing Setting(s)", JOptionPane.ERROR_MESSAGE);
        return;
    }

    // Cerrar diálogo.
    dispose();
}

// Cancelar la conexión y salir del programa.
private void actionCancel() {
    System.exit(0);
}

     //Obtener servidor de correo electrónico
public String getType(){
   return(String) typeComboBox.getSelectedItem();
}

// Obtener servidor de correo electrónico
public String getServer() {
    return serverTextField.getText();
}

// Obtener un nombre de usuario de correo electrónico.
public String getUsername() {
    return usernameTextField.getText();
}

// Obtener contraseña de correo electrónico.
public String getPassword() {
    return new String(passwordField.getPassword());
}

// Obtener correo electrónico del servidor SMTP.
public String getSmtpServer() {
    return smtpServerTextField.getText();
}
}

I see an error in those lines 166 and I do not know what it could be, apart from that in the "Get email server" it asks me to put the Override and when I put it it asks me to remove it and it is the only error that marks me in the netbeans, any idea why it will be?

    
asked by Chivo Alvarado 09.08.2017 в 21:02
source

1 answer

2

The problem is that as you inherit from JDialog you are writing about a method of Windows as indicated by the error.

When you use the solution proposed by Netbeans you do not really fix the problem because you can not overwrite that method by returning a different data type.

The solution is to change the name to the method maybe by:

public String getProtocolType() {
        return (String) typeComboBox.getSelectedItem();
    }
    
answered by 09.08.2017 в 23:10