Weird error in Eclipse: it works, but the red underline appears in JOptionPane

1

I started programming in Eclipse. I have an error in the code I wrote (see the comments in the code):

import javax.swing.*;
public class SumaConJOptionPane {
    public static void main(String[] args) {

        String usuario, aux1, aux2;
        int a, b;
        //                          Se solicita nombre de usuario

        usuario = JOptionPane.showInputDialog("Ingrese nombre de usuario");
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


        //                          muestra el nombre y le indica al usario que se va a hacer una suma

        JOptionPane.showMessageDialog(null, "Muy bien " + usuario + "! V    amos a hacer una suma");
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        //                          A continuacion solicita el ingreso del primer numero

        aux1 = JOptionPane.showInputDialog("Ingresa un numero: ");
        a = Integer.parseInt(aux1); // En esta linea lo que hace es convertir al 'string' del JOptionPane en un 'int'
        // con el metodo Integer.parseInt(aqui va la variable del JOptionPane)

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


        //                          Solicita el segundo numero

        aux2 = JOptionPane.showInputDialog("Ingresa el otro numero: ");
        b = Integer.parseInt(aux2); // En esta linea lo que hace es convertir al 'string' del JOptionPane en un 'int'
        // con el metodo Integer.parseInt(aqui va la variable del JOptionPane

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        //                          Finalmente nombra al usuario, muestra los numeros ingresados, y el resultado de la suma entre dichos numeros

        JOptionPane.showMessageDialog(null, "Bien " + usuario + "! " + a + " + " + b + " es igual a " + (a + b) + "");
    }
}

What happens is ... it works, but anyway the red underline appears in the JOptionPane indicating an error, but it works anyway!

Can anyone tell me what it could be? I do not know if it will be syntax or the JRE or JDK, I already reviewed them and they are all in the same version.

    
asked by 6aston5 11.12.2016 в 04:35
source

1 answer

0

The code that you have pasted in your question, is perfect, there are no errors in it. I think I have a suspicion that I was marking you in red in the JOptionPane because you still did not import the class .

import javax.swing.*;

That you could simply import it as well, since when using the asterisk (*) it imports all the classes of the Swing library :

import javax.swing.JOptionPane;

I do not think that you have clicked on the error button that Eclipse shows you, because if you had done it, you would only care about the class as I wrote it here in the second way.

    
answered by 11.12.2016 / 05:24
source