juliee
juliee

Reputation: 55

Convert String in Int

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();
    }         

Upvotes: 0

Views: 102

Answers (2)

AndrejH
AndrejH

Reputation: 2109

Use Integer.parseInt("123456").

Upvotes: 5

Keshan Nageswaran
Keshan Nageswaran

Reputation: 8178

Use Integer.valueOf("string") as alternative too! This will return an Integer object.

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

Upvotes: 3

Related Questions