我的组合框中有一个字符串,我想使用它,但是以某种方式我收到此错误

时间:2019-12-03 13:23:17

标签: java javafx

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package herkansing;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import javafx.stage.Stage;





public class NummerController implements Initializable {
    // creating buttons at FXML

    @FXML   private Button Homepage;    
    @FXML   private Button create;    
    @FXML   private Button read;    
    @FXML   private Button update;   
    @FXML   private Button delete;

    // creating textfields at FXML

    @FXML   private TextField txtID;
    @FXML   private TextField txtTitel;
    @FXML   private TextField txtDuur;


    @FXML   private ComboBox <String> cmbCD;


    // connecting function add button to database

    private Database db;


    public void create_nummer (ActionEvent event) {
        Database db = new Database();

            int ID = Integer.parseInt(txtID.getText());
            String titel  = txtTitel.getText();
            String duur  = txtDuur.getText();
            String CDTitel  = (cmbCD.getValue());


            db.addNummer(ID, titel, duur, CDTitel);
            //txtlijkID.clear();
            txtID.clear();
            txtTitel.clear();
            txtDuur.clear();

            ObservableList<String> lijst = db.getCD();
            cmbCD.setItems(lijst);


    }

    //connecting function read button to database

    public void read_nummer (ActionEvent event) {
        //Database db = new Database();


        //int lijkID = Integer.parseInt(txtlijkID.getText());
        txtID.setText(db.getID(cmbCD));
        txtTitel.setText(db.getTitel(cmbCD));
        txtDuur.setText(db.getDuur(cmbCD));
        String CDTitel  = (cmbCD.getValue());
    }

    // connecting function update button to database

    public void update_nummer (ActionEvent event) {
        Database db = new Database();

        int ID = Integer.parseInt(txtID.getText());
        String titel = txtTitel.getText();
        String duur = txtDuur.getText();
        String CDTitel  = (cmbCD.getValue());


            db.updateNummer(ID, titel, duur, CDTitel);


            txtID.clear();
            txtTitel.clear();
            txtDuur.clear();

    }

    //connecting function delete button to database

    public void delete_nummer (ActionEvent event) {
        Database db = new Database();
        String CDTitel  = (cmbCD.getValue());
        db.verwijderNummer(cmbCD);

        txtID.clear();
        txtTitel.clear();
        txtDuur.clear();

    }

    //creating function button homepage to get back to homepage

 public void terug_Homepagina (ActionEvent event) throws IOException {
        Parent Homepage_parent = FXMLLoader.load(getClass().getResource("Homepage.fxml"));
        Scene Homepage_scene = new Scene(Homepage_parent);
        Stage App_stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
        App_stage.setScene(Homepage_scene);       App_stage.show();
    }

    /**
     * Initializes the controller class.
     */
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO

         db = new Database();
         ObservableList<String> lijst = db.getCD();

        cmbCD.setItems(lijst);
    }    

}
C:\Users\rafik\Documents\NetBeansProjects\Herkansing\src\herkansing\NummerController.java:80: error: incompatible types: ComboBox<String> cannot be converted to String
        txtID.setText(db.getID(cmbCD));
C:\Users\rafik\Documents\NetBeansProjects\Herkansing\src\herkansing\NummerController.java:81: error: incompatible types: ComboBox<String> cannot be converted to String
        txtTitel.setText(db.getTitel(cmbCD));
C:\Users\rafik\Documents\NetBeansProjects\Herkansing\src\herkansing\NummerController.java:82: error: incompatible types: ComboBox<String> cannot be converted to String
        txtDuur.setText(db.getDuur(cmbCD));
C:\Users\rafik\Documents\NetBeansProjects\Herkansing\src\herkansing\NummerController.java:111: error: incompatible types: ComboBox<String> cannot be converted to String
        db.verwijderNummer(cmbCD);
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
4 errors
C:\Users\rafik\Documents\NetBeansProjects\Herkansing\nbproject\build-impl.xml:931: The following error occurred while executing this line:
C:\Users\rafik\Documents\NetBeansProjects\Herkansing\nbproject\build-impl.xml:271: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 0 seconds)

0 个答案:

没有答案