Error solving Handler Javafx method inside classeDAO and controler with Mysql database

Asked

Viewed 206 times

1

I am trying to create a simple cash system (cash entries minus cash outputs equal balance). And I made a method in class Dismissed going to the bank with the personalized consultation:

(SELEC SUM(VALOR) FROM DESPESA WHERE VALOR IS NOT NULL AND DATA='USUARIO ESCOLHE')

In class Fired like this:

public Despesa somarValoresDespesa(Despesa despesa, LocalDate data){
    String sql = "SELECT SUM(valor) FROM despesa WHERE valor IS NOT NULL AND data=?";
    //double soma = 0.0;
    Despesa retorno = new Despesa();
    data = despesa.getData();
    try{
        PreparedStatement stmt = conexao.prepareStatement(sql);
        stmt.setDate(1, Date.valueOf(data));//Estava "Date.valueOf(data)"
        ResultSet resultado = stmt.executeQuery();
        while (resultado.next()){
           double soma = resultado.getDouble(1);
           despesa.setValor(soma);
           retorno = despesa;
        }
    }catch (SQLException ex){
        Logger.getLogger(DespesaDAO.class.getName()).log(Level.SEVERE, null, ex);
    }
    return retorno;
}

And on the controller so:

@FXML
public void somaVlrDespesa(Despesa despesa, LocalDate data) throws IOException {
    //Despesa despesa = new Despesa();
    //LocalDate data;
    data = dtData.getValue();
    if(despesa != null && data != null){
        despesa = despesaDAO.somarValoresDespesa(despesa, data);
        txValorTotalDespesas.setText(String.valueOf(despesa.getValor()));
        System.out.println(despesa);
    } else {
        dtData.setValue(LocalDate.now());
        txValorTotalDespesas.setText(" ");
    }
}

In the view that controller has a button and a text box. Then the user chooses the date and clicks on the button and the method makes the query and SHOULD set in the box the value brought from the bank. SHOULD. But you’re making that exception:

   Caused by: javafx.fxml.LoadException: Error resolving onAction='#somaVlrDespesa',
either the event handler is not in the Namespace or there is an error in the script.
file:/D:/Caxa-Renova/cxren/dist/run1293869844/cxren.jar!/cxren/view/FXMLAnchorPaneCadastroDespesa.fxml:54
    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2597)
    at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:103)
    at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:610)
    at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:770)
    at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2823)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2532)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
    at cxren.controller.FXMLVBoxPrincipalController.eventoBotaoAbrirCadastroDespesa(FXMLVBoxPrincipalController.java:38)
    ... 58 more

He says he can’t find the method #somaVlrDespesa. But FXML is saved correctly and if I put something in place to exit (System.Exit(0)) does not give error.

What can it be?

If you need all the classes, I’ll send.

UPDATING follows the FXML of this controller

 <?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane id="AnchorPane" fx:id="ancorPane" prefHeight="600.0" prefWidth="1200.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="cxren.controller.FXMLAnchorPaneCadastroDespesaController">
   <children>
      <SplitPane dividerPositions="0.7587646076794657" layoutX="6.0" layoutY="104.0" prefHeight="484.0" prefWidth="1200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="50.0">
        <items>
          <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="548.0" prefWidth="432.0">
               <children>
                  <TableView fx:id="tbCadastroDespesa" prefHeight="550.0" prefWidth="906.0">
                    <columns>
                      <TableColumn fx:id="tbColunaData" prefWidth="91.0" text="DATA" />
                      <TableColumn fx:id="tbColunaNome" prefWidth="123.0" text="NOME" />
                        <TableColumn fx:id="tbColunaValor" prefWidth="109.0" text="VALOR" />
                        <TableColumn fx:id="tbColunaDescrição" prefWidth="581.0" text="DESCRIÇÃO" />
                    </columns>
                  </TableView>
               </children>
            </AnchorPane>
            <AnchorPane prefHeight="160.0" prefWidth="514.0">
               <children>
                  <DatePicker fx:id="dtData" layoutX="97.0" layoutY="49.0" prefHeight="25.0" prefWidth="175.0" />
                  <ComboBox fx:id="cbNome" layoutX="97.0" layoutY="117.0" prefHeight="25.0" prefWidth="175.0" promptText="Escolha o Tipo..." />
                  <TextField fx:id="txValor" layoutX="97.0" layoutY="201.0" prefHeight="25.0" prefWidth="175.0" />
                  <TextField fx:id="txDescrição" layoutX="97.0" layoutY="319.0" prefHeight="25.0" prefWidth="175.0" />
                  <Button fx:id="btCadInserir" layoutX="97.0" layoutY="439.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="175.0" text="INSERIR" AnchorPane.rightAnchor="14.0" />
                  <Label layoutX="14.0" layoutY="53.0" text="DATA" />
                  <Label layoutX="14.0" layoutY="121.0" text="NOME" />
                  <Label layoutX="14.0" layoutY="204.0" text="VALOR" />
                  <Label layoutX="14.0" layoutY="323.0" text="DESCRIÇÃO" />
                  <Button fx:id="btCadDespesaVoltar" layoutX="220.0" layoutY="509.0" mnemonicParsing="false" onAction="#eventoBotaoVoltarInicio2" prefHeight="25.0" prefWidth="53.0" text="&lt;--" AnchorPane.rightAnchor="14.0" />
                  <Label alignment="CENTER" layoutX="106.0" layoutY="513.0" text="Voltar ao Inicio">
                     <font>
                        <Font name="System Italic" size="12.0" />
                     </font>
                  </Label>
               </children>
            </AnchorPane>
        </items>
      </SplitPane>
      <Label layoutX="14.0" layoutY="14.0" text="CADASTRO DE ITENS DE DESPESA - CAIXA RENOVA" textFill="#5341ab">
         <font>
            <Font name="System Bold" size="18.0" />
         </font>
      </Label>
      <Label layoutX="811.0" layoutY="19.0" text="TOTAL DAS DESPESAS:" />
      <TextField fx:id="txValorTotalDespesas" layoutX="940.0" layoutY="15.0" prefHeight="25.0" prefWidth="175.0" />
      <Button fx:id="btCarregaValor" layoutX="496.0" layoutY="15.0" mnemonicParsing="false" onAction="#somaVlrDespesa" text="MOSTRA TOTAL DE DESPESAS POR DATA" />
   </children>
</AnchorPane>

Thank you. PLACING REQUESTED IMPORTS

mport cxren.model.dao.DespesaDAO;
import cxren.model.database.BancoDeDados;
import cxren.model.database.DatabaseFactory;
import cxren.model.domain.Despesa;
import java.io.IOException;
import java.net.URL;
import java.sql.Connection;
import java.time.LocalDate;
import java.util.List;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane;
  • Put the fxml that uses this controller.

  • Renan edited the query and put FXML. Thank you.

  • It could also include class Imports FXMLAnchorPaneCadastroDespesaController? So far everything seems okay in your code.

  • Renan this is the Imports. Thanks.

No answers

Browser other questions tagged

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