Data acquisition by Jtable

Asked

Viewed 68 times

0

I’m trying to get JButtonGuardar(panelInserir) pass user input(local time text) of the JPanelInserir to the JPanelEventos(where is Jtable)

At the moment, I am not succeeding, if you have any suggestions I leave to follow the code of where the problem is occurring:

error: Exception in thread "AWT-Eventqueue-0" java.lang.Nullpointerexception at net.ruimendes.Try$8.actionPerformed(Try.java:417)

Code of where the error is occurring:

JButton btnGuardar = new JButton("Guardar");
btnGuardar.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        try {
            double hora = Double.parseDouble(textHoraInicio.getText());
            String texto = textTexto.getText();
            String local = textLocal.getText();
            Agendado agen = new Agendado(hora, texto, local);
            eventoAtual.adicionaAgendado(agen);
            textHoraInicio.setText(String.format("%.2f", eventoAtual.getHora()));
            textHoraInicio.setText("");
            textTexto.setText("");
            textLocal.setText("");
        } catch (NumberFormatException e1) {

            e1.printStackTrace();
        } catch (AgendadoNuloException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }


    }
});

The complete code is at this link

  • Rui, as much as adding the complete source is sometimes a facilitator to locate the problem, it is also important that you post on the question itself, a [mcve], with a more localized and smaller portion of the problem, it is even easier for people to help you. With giant codes, many discourage.

  • Hint, try to debug your code and locate the source of the error (or as close as you can identify). Your code has more than 200 lines, imagine the work it takes to analyze a code like this.

  • I have already put the part corresponding to the respective button

  • What error does it give? Add to the question what problems you are having, error messages that appear.

1 answer

1


The problem is because you declared the variable eventoAtual at the beginning of the class, but did not start it or assign any object to it. Therefore, when you call it in this action, the variable is null.

Not to mention that you are starting local variable of the same name as your already cited attribute(check the method escolheNovoEvento), maybe this is why the variable is never started.

I’ve answered about this kind of problem in another answer, read the explanation and review your code for this type of problem.

  • I’m sorry but I don’t understand what I have to do:(

  • @Ruimendes gives a close read to the link I put in the answer, there you will have a brief explanation about the problem of your code. Then look at the method I indicated here. If after that do not understand, just speak here :)

  • is what I’ve done, I’ve been reading but apparently I’m not yet in the technical terms, then I went to the chooseNoveEvento I tried to change some things there and it keeps going wrong, and the program does not put this data I indicate in the page I want....

  • @Ruimendes ao faze eventoAtual.adicionaAgendado(agen); you are trying to add an agenda to an event you haven’t even created yet. Where in your code you have created a evenAtual to make that call?

  • Private entries eventAtual; no public void chooseNoveEvento(Try catch Finally); so here I think... otherwise this is not what to create anymore :(

  • There’s the problem. You’re not calling this method at any point in your class. So, no event exists when you click the button.

  • have any suggestions? I am trying to guide myself by my teacher’s code but at this point the projects are different

  • @Ruimendes can’t even answer you, because to do so, I would have to study your entire project and understand how it works. This would be too expensive. : / Unfortunately, the most recommended thing is that you ask your teacher, because he already understands how your project should work and can give you a faster and more accurate answer.

  • had to deliver this by yesterday, and he decided not to reply to emails all week xD I’m trying to ahah thank you

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.