[RESOLVIDO] Erro no código. Java swing

Bom domingo à todos! Enfim, meu código não está pronto. Eu tentei executá-lo porém ocorreu um erro e agora não consigo indentificar onde o “bemdito” está. Alguém poderia me mostrar o que eu fiz de errado?

package imc;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import java.awt.Color;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ImcMainClass extends JFrame {

	private SecunClass  Clas = new SecunClass(this);
	
	private static final long serialVersionUID = 1L;
	
	//Autor: Joao Vitor Souza Pioner | Data: 7/11/2020 16:36
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ImcMainClass frame = new ImcMainClass();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public JPanel contentPane;
	public JTextField txtAltura;
	public JLabel lblAltura;
	public JTextField txtResultado;
	public JTextField txtPeso;
	public JTextField txtSexo;
	public JTextField txtAuxilio;
	
	public ImcMainClass() {
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 341, 347);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(95, 158, 160));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		//labels
		JLabel lblResultado = new JLabel("Resultado: ");
		lblResultado.setForeground(new Color(255, 255, 255));
		lblResultado.setBackground(new Color(255, 255, 255));
		lblResultado.setFont(new Font("Comic Sans MS", Font.BOLD, 20));
		lblResultado.setBounds(10, 212, 111, 19);
		contentPane.add(lblResultado);
		
		JLabel lblMainIMC = new JLabel("Calculando IMC");
		lblMainIMC.setForeground(new Color(240, 248, 255));
		lblMainIMC.setFont(new Font("Comic Sans MS", Font.BOLD, 22));
		lblMainIMC.setBounds(76, 11, 167, 36);
		contentPane.add(lblMainIMC);
		
		JLabel lblPeso = new JLabel("Peso:");
		lblPeso.setFont(new Font("Comic Sans MS", Font.PLAIN, 20));
		lblPeso.setForeground(new Color(255, 255, 255));
		lblPeso.setBounds(10, 128, 54, 19);
		contentPane.add(lblPeso);
		
		lblAltura = new JLabel("Altura:");
		lblAltura.setForeground(Color.WHITE);
		lblAltura.setFont(new Font("Comic Sans MS", Font.PLAIN, 20));
		lblAltura.setBounds(10, 164, 71, 19);
		contentPane.add(lblAltura);
		
		JLabel lblSexo = new JLabel("Sexo (F/M):");
		lblSexo.setForeground(Color.WHITE);
		lblSexo.setFont(new Font("Comic Sans MS", Font.PLAIN, 20));
		lblSexo.setBounds(10, 88, 125, 19);
		contentPane.add(lblSexo);
		
		//txtboxs
		txtAltura = new JTextField();
		txtAltura.setColumns(10);
		txtAltura.setBounds(76, 156, 140, 27);
		contentPane.add(txtAltura);
		
		txtResultado = new JTextField();
		txtResultado.setBounds(115, 204, 101, 27);
		contentPane.add(txtResultado);
		txtResultado.setColumns(10);
		
		txtPeso = new JTextField();
		txtPeso.setColumns(10);
		txtPeso.setBounds(64, 118, 152, 27);
		contentPane.add(txtPeso);
		
		txtSexo = new JTextField();
		txtSexo.setColumns(10);
		txtSexo.setBounds(127, 80, 89, 27);
		contentPane.add(txtSexo);
		
		txtAuxilio = new JTextField();
		txtAuxilio.setBounds(10, 242, 206, 54);
		contentPane.add(txtAuxilio);
		txtAuxilio.setColumns(10);
		
		//botton
		JButton btnCalcular = new JButton("Calcular");
		btnCalcular.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				Clas.VerificandoIMC();
			}
		});
		btnCalcular.setForeground(new Color(119, 136, 153));
		btnCalcular.setFont(new Font("Comic Sans MS", Font.BOLD, 14));
		btnCalcular.setBackground(new Color(102, 205, 170));
		btnCalcular.setBounds(226, 80, 91, 103);
		contentPane.add(btnCalcular);
		
		JButton btnLimpar = new JButton("Limpar");
		btnLimpar.setForeground(new Color(119, 136, 153));
		btnLimpar.setFont(new Font("Comic Sans MS", Font.BOLD, 14));
		btnLimpar.setBackground(new Color(102, 205, 170));
		btnLimpar.setBounds(226, 204, 91, 92);
		contentPane.add(btnLimpar);
	
	}
}

Outra classe:

package imc;

public class SecunClass {
	
	final ImcMainClass mNC;

	public SecunClass(ImcMainClass mnC) { // recebe a tela como parâmetro ao invés de instanciar novamente
		this.mNC = mnC;
	}
	
	public double CalculandoIMC() {
		
		double peso = Double.parseDouble(mNC.txtPeso.getText().replaceAll(",", ".")); //replaceAll serve para alterar caracteres
		double altura = Double.parseDouble(mNC.txtAltura.getSelectedText().replaceAll(",", "."));
		
		return peso / (Math.pow(altura, 2)); 
	}
	
	public void VerificandoIMC() {
		
		if (mNC.txtSexo.getText().equals("F")) {
			if (CalculandoIMC() < 19) {
				mNC.txtAuxilio.setText("Magreza. Seu IMC deveria ser entre 19 e 23.9");
				mNC.txtResultado.setText("" + CalculandoIMC()); //passei para String
			}
		}
	}
}

Se debugar e ir inspecionado pelo menos vai encontrar onde tá com problema.

Se fizesse ia saber.

Vc precisa nos dizer o que está acontecendo e onde. Qual é o erro?

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at imc.SecunClass.CalculandoIMC(SecunClass.java:14)
	at imc.SecunClass.VerificandoIMC(SecunClass.java:22)
	at imc.ImcMainClass$2.actionPerformed(ImcMainClass.java:119)
	at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
	at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
	at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
	at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
	at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
	at java.desktop/java.awt.Component.processMouseEvent(Component.java:6635)
	at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
	at java.desktop/java.awt.Component.processEvent(Component.java:6400)
	at java.desktop/java.awt.Container.processEvent(Container.java:2263)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5011)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843)
	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
	at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2772)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

oq tem nessa linha acima?

Era ali o erro mano, obrigado de coração

Não entendi, vc resolveu?

SIm, eu não tinha visto. Em vez de eu pôr getText() eu botei getSelcetText()

1 curtida