Convert String in Int

时间:2018-05-28 18:54:31

标签: java string

In my private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) I have error message:

incompatible types: String cannot be converted to int

My first field (IdentCat) is normaly an Int. However I don't know how to do this in INT ?

ap.setIdentCat(jTextIdent.getText().toUpperCase());

More of code

private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        Categorie ap = new Categorie();
        ap.setIdentCat(jTextIdent.getText().toUpperCase());
        ap.setDenomCat(jTextDescr.getText());

        boolean ok = daoCat.insertCategorie(ap);
        if (!ok)
            JOptionPane.showMessageDialog(null,"Insertion impossible !","Avertissement",JOptionPane.ERROR_MESSAGE);
        this.dispose();
    }         

2 个答案:

答案 0 :(得分:5)

Use Integer.parseInt("123456").

答案 1 :(得分:3)

也可以使用Integer.valueOf("string")作为替代!这将返回一个Integer对象。

String number = "10";
Integer result = Integer.valueOf(number);