|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Jun 2000
Città: Nowhere
Messaggi: 109
|
Java: parseInt() non funziona
Di per se il programma e' una banalita', peccato che non funzioni
Leggo da Standard Input una stringa contenente un numero e poi lo converto in intero con parseInt... pero' il compilatore mi da un errore proprio relativo al comando in oggetto import java.io.*; class prova { public static void main (String[] args) throws IOException { InputStreamReader lettore = new InputStreamReader (System.in); BufferedReader myInput = new BufferedReader (lettore); String str= new String(); try { str = myInput.readLine(); } catch (IOException e) { System.out.println ("Si è verificato un errore: " + e); System.exit(-1); } System.out.println("Hai digitato: " + str); int num; num=str.parseInt(); .... } L'errore ottenuto e' il seguente: cannot resolve symbol symbol: method parseInt () location: class.java.lang.String num=str.parseInt();
__________________
"Among the winners, there is no room for the weak." |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Oct 2000
Messaggi: 235
|
Controlla che la stringa inserita contenga solo caratteri numerici.
Prova anche a stampare lo stack delle chiamate quando capita l'eccezzione. Bye
__________________
...writing about climbing is boring. I would rather go climbing. (Chuck Pratt) |
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Jun 2000
Città: Nowhere
Messaggi: 109
|
Segnala l'errore in fase di compilazione, non mentre sto eseguendo il programma
__________________
"Among the winners, there is no room for the weak." |
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Jan 2000
Città: Milano
Messaggi: 1034
|
La classe String che io sappia non ha nessun metodo parsInt
parsInt è un metodo statico della classe Integer... Integer.parsInt(String s) basta guardare la documentazione Java... |
|
|
|
|
|
#5 | |
|
Senior Member
Iscritto dal: Jun 2000
Città: Nowhere
Messaggi: 109
|
Quote:
__________________
"Among the winners, there is no room for the weak." |
|
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: Feb 2002
Città: Milano
Messaggi: 1405
|
per convertire una string in un intero devi scrivere la seguente riga di comando String str1 = Integer.parseInt("str");
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 04:23.


















